如何在Github上的jupyter笔记本中嵌入pdfs文件

时间:2018-02-15 20:55:03

标签: python pdf jupyter-notebook

所以我有几个pdfs文件,我上传到我在Github上的存储库。现在我在github上与pdf文件在同一目录中的jupyter笔记本文件,并希望在jupyter笔记本中显示pdf。

我使用以下方法在笔记本中嵌入pdf。

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

现在,当我在我的本地笔记本电脑上执行此操作时,同样的事情是可行的,我将pdf存储在目录中并将其链接到笔记本电脑上的jupyter笔记本文件。我也可以看到pdfs内联。

然而,当我在Github上做同样的事情时,它没有显示pdfs并得到以下内容:

enter image description here

所以我不确定为什么它无法链接存储在github上相同存储库中的pdf,并在我的本地系统上工作时显示它们

有任何帮助吗?

由于

1 个答案:

答案 0 :(得分:0)

在Github的情况下,这是因为X-Frame-Options限制。

请参阅:iframe not rendering in ipython-notebook

作为解决方法,您可以尝试使用rawgit.com:

示例:

https://raw.githubusercontent.com/mozilla/pdf.js/raw/master/test/pdfs/S2.pdf(不起作用)

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