Open jfparie opened 3 years ago
@jfparie Seems correct. Could you please share a link to your repository. This repo is for the demo website of Hugo Embed PDF shortcode. You could refer the code in this repository and compare it with your code. The shortcode is hosted at this repository
@anvithks Thanks for your response :-) Here is the link to the repository of my website where I want to use Hugo Embed PDF shortcode. I call the short code only in a .md markdown file by using the following command:
{{< embed-pdf url="./uploads/file_name.pdf" >}}
My issue has great similarities to issue #18. However, I was not able to solve the issue based on the mentioned work around by Arwhyte .
Note I cloned your repository by using git clone https://github.com/anvithks/hugo-embed-pdf-shortcode.git
outside my website's repository, then I copied and pasted the earlier mentioned files in the above tree structure.
Thanks for looking into this!
One thing I see is that the PDF file is not located with the .md file where it is included. Currently this is a limitation for which I am yet to get a proper solution. Another thing I noticed is that clicking on http://algorithmaudit.eu/ opens a site not found error page. This is the baseURL specified in the config.toml file. Could you please share the link to the website and page where you are including the pdf?
Hi @anvithks, thanks for your reply :-)
{{< embed-pdf url="file_name.pdf" >}}
but this doesn't seem to work. The same Failed to load resource: net::ERR_NAME_NOT_RESOLVED
and Uncaught TypeError
occur.@jfparie I cloned your repository and by making a few changes I was able to get the pdf to display. You are right. It is related to the src and baseURL. The changes I made were:
config/_default/config.toml
with baseURL = "/"
(In understand the config.toml in the root overrides this. If yes, then you can make the change outside.){{< embed-pdf url="./file_name.pdf" >}}
<script type="text/javascript" src= '/js/pdf-js/build/pdf.js'></script>
var url = '{{ .Get "url" }}';
pdfjsLib.GlobalWorkerOptions.workerSrc = '/js/pdf-js/build/pdf.worker.js';
With these changes I am able to see the pdf file.
This problem arises when we use the baseURL and try to build locally or do not specify one and try to build locally. I have not been able to spend a lot of time recently and have not been able to put out a fix. The code works when deployed on the actual baseURL.
I will try to fix this but in the meanwhile you can try the following:
Best, Anvith.
Many thanks for fixing this! I will take a careful look later. Would you mind to remove the image previewing the document (the document should remain undisclosed)? Many thanks again :-)
@jfparie sure. I have removed the screenshot. Let me know if you are able to get it to work.
Chrome browser 95.0.4638.69 gives the following error:
Cannot read properties of undefined (reading 'GlobalWorkerOptions') at window.onload ((index):256)
I copied
./layouts/shortcodes/embed-pdf.html
to my own/layouts/shortcodes
folder. The same from pdf.js library files from./static/js/pdf-js
to./static/js
. Is the following path structure correct?- static
-- js
--- pdf-js
---- build
----- pdf.js
----- pdf.js.map
----- pdf.worker.js
----- pdf.worker.js.map
---- LICENSE
---- web
----- cmaps
etc.