简体   繁体   中英

How to embed pdfs files in jupyter notebook on Github

So I have few pdfs files which I uploaded to my repository on Github. Now I am uploding a jupyter notebook file in the same directory as the pdf files on github and want to display pdfs inside the jupyter notebook.

I used the following method to embed pdfs in a notebook.

from IPython.display import IFrame
IFrame("https://github.com/user/first.pdf", width=900, height=800)

Now the same thing works when I do this on my local laptop where I store the pdfs in a directory and link that to the jupyter notebook file on my laptop. I can see the pdfs inline too.

However when I do the same thing on Github, it doesn't show the pdfs and get the following thing:

在此处输入图像描述

So am not sure why it is not able to link the pdfs stored on the same repository on github and display them while it works on my local system

Any help?

Thanks

In the case of Github, it is because of X-Frame-Options restriction.

See: iframe not rendering in ipython-notebook

As a workaround, you can try using rawgit.com:

Example:

https://raw.githubusercontent.com/mozilla/pdf.js/raw/master/test/pdfs/S2.pdf (does not work)

https://rawgit.com/mozilla/pdf.js/master/test/pdfs/S2.pdf (works)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM