anvithks / hugo-embed-pdf-shortcode

A shortcode for Hugo(https://gohugo.io/) which allows you to embed a PDF file in a page using Pdf.js (https://mozilla.github.io/pdf.js/)
https://hugo-embed-pdf.netlify.app/
MIT License
133 stars 53 forks source link

PDF always loading, never displaying. #36

Open corei8 opened 1 year ago

corei8 commented 1 year ago

The initial installation did not work at all. But then I ran across this guide and I can get the shortcode to start loading the PDF, but it never actually loads it: the wheel just keeps on spinning.

sysadmin-info commented 1 year ago

For me it is working only locally when I run the hugo server. On my website https://sysadmin.info.pl/pl/blog/moja-praca-inzynierska/ it does not work. the repository from github is taken by netlify and I added my custom domain. I have no idea is it possible to add CORS to netlify.

sysadmin-info commented 1 year ago

I know the solution. First of all in my case I had to change in config.toml a base URL to this baseURL = "/"

Then in the netlify.toml (because I am using netlify) I had to define headers this way:

[build]
  command = "hugo"
  publish = "public"

[build.environment]
  HUGO_VERSION = "0.111.3"

[[headers]]
  for = "/*"
    [headers.values]
    Access-Control-Allow-Origin = "sysadmin.info.pl"

After that in my md file where I am using a shortcode I defined it this way:

{{< embed-pdf url="../../../files/document.pdf" renderPageNum="1" >}}

Because I keep the PDF file in the directory

/root dir of my site/static/files

And my md file where I am using the shortcode is located here:

/root dir of my site/content/pl/blog

This way I solved the problem. I think you can try. If you have any questions, do not hesitate to ask me, please.

anvithks commented 1 year ago

@corei8 @sysadmin-info You can take a look at how the shortcode is embedded and the Hugo site config in the demo site here

This site is built with the minimal theme and is deployed using Netlify.

sysadmin-info commented 1 year ago

@corei8 @sysadmin-info You can take a look at how the shortcode is embedded and the Hugo site config in the demo site here

This site is built with the minimal theme and is deployed using Netlify.

I figured it out. In the config.toml where the base url is defined instead of / it has to be https://example.com/ not https://example.com or / The / at the end of the address is crucial.

sysadmin-info commented 1 year ago

The initial installation did not work at all. But then I ran across this guide and I can get the shortcode to start loading the PDF, but it never actually loads it: the wheel just keeps on spinning.

I figured it out. In the config.toml where the base url is defined instead of / it has to be https://example.com/ not https://example.com or / The / at the end of the address is crucial.

ai4bing commented 10 months ago

I also have this issue even when using

hugo server --baseURL "/"
sysadmin-info commented 9 months ago

I also have this issue even when using

hugo server --baseURL "/"

Read one more time carefully my answer. I figured it out. In the config.toml where the base url is defined instead of / it has to be https://example.com/ not https://example.com or / The / at the end of the address is crucial. So instead / use your base address with / at the end eg. https://sysadmin.info.pl/