anvithks/hugo-embed-pdf-shortcode

how to set a pdf file so that it can display?

Dicky1 opened this issue · 14 comments

Screenshot_20210305_224426

I tried the inspect element on the Hugo blog page, an error appeared like the picture

{{< embed-pdf url="./path/to/pdf/file/LAPORAN HASIL MONITORING KEAMANAN SIBER TAHUN 2020.pdf" >}}

is it correct to set the url?

@Dicky1 have you followed the steps to setup the short code correctly?
Is this on your local machine or a VM?
From the error it seems that the PdfJsLib is blocked.

@Dicky1
After you have setup the shortcode correctly you have to place the pdf file in the content folder where the document exists and specify the relative path to that folder.
For ex:
if your hugo site is in a folder called blog-hugo this would be an example code.
This would be a sample document /blog-hugo/content/demo-page/index.md
Your pdf file should be in the same folder as follows:
/blog-hugo/content/demo-page/LAPORAN HASIL MONITORING KEAMANAN SIBER TAHUN 2020.pdf

and in the index.md file you should use the shortcode as follows:

{{< embed-pdf url="./LAPORAN HASIL MONITORING KEAMANAN SIBER TAHUN 2020.pdf" >}}

Another suggestion: avoid having spaces in the file name of the PDF file. You can use - or _ like
LAPORAN_HASIL_MONITORING_KEAMANAN_SIBER_TAHUN_2020.pdf

Screenshot_20210306_022038

still the same pdf file does not appear

Have you copied the pdf-js files as per step 3 in the setup here?

Already, is it possible that my pdf file is too big?

Already, is it possible that my pdf file is too big?

What is the size of the file?
I do not think the error that you are seeing is because of that.
is it possible to push your code and share the repository with me?
I can test it locally and check if there is something that needs to be fixed.

Github

that's my repository for this problem

@Dicky1 Got it. I pulled your repository.
One thing that needs to be fixed in your repository is in the JS folder here https://github.com/Dicky1/hugo-blog/tree/main/static/js

The build, web folders and LICENSE should be inside a folder called pdf-js.
You can take a look at the demo here

Your pdf file is OK.
I checked it on my local dev env. The filename without spaces is not a problem.

image

I've moved the file in the pdf-js folder I think it's still the same

Screenshot_20210308_122459

may check my latest repository

blog-hugo

I figured it out.
The PDF file is inside the /post folder.
image

This is the folder structure.
image

Move the PDF file under /post folder.
{{< embed-pdf url="./post/LAPORAN HASIL MONITORING KEAMANAN SIBER TAHUN 2020.pdf" >}}

if you want to maintain all resources under one folder then you can create a file/ folder under the post folder.

oke solved thanks

Closing since the issue was resolved.