pdf.js是否只适用于某些pdf? [英] Does pdf.js only work with certain pdfs?

查看:110
本文介绍了pdf.js是否只适用于某些pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pdf.js 将pdf页面转换为画布。我在使用.pdf渲染到单个画布时使用了答案由K3N实现的pdf.js和ImageData 。代码可在此处 Fiddle1

I am trying to convert pdf pages to canvas using pdf.js. I used the answer in Render .pdf to single Canvas using pdf.js and ImageData by K3N to achieve this. The code is avaliable here Fiddle1.

问题是这似乎只适用于某些pdf。

The problem is that this seems to work with certain pdfs only.

例如,代码适用于 http :http://arxiv.org/pdf/1207.0102v2.pdf Fiddle2 中。

For example the code works fine for http://arxiv.org/pdf/1207.0102v2.pdf in Fiddle2.

然而,当我为 http://infolab.stanford.edu/pub/papers/google.pdf >小提琴3 它无法奏效。

However, when I tried the same code for http://infolab.stanford.edu/pub/papers/google.pdf in Fiddle3 it failed to work.

为什么会发生这种情况并修复?

Why is this happening and can it be fixed?

推荐答案

它应该适用于所有pdf文件,除非它们已损坏。你在这里遇到的错误是:

It is supposed to work with all pdf files, unless they are corrupted. The error you have here is:


XMLHttpRequest无法加载http://infolab.stanford.edu/pub/论文/ google.pdf。请求的资源上不存在Access-Control-Allow-Origin标头。因此,不允许访问http://fiddle.jshell.net。

在其他单词,你不能这样加载它,因为 http://infolab.stanford.edu/pub/papers/google.pdf 不允许你这样做。如果您将它放在服务器上并使用适当的响应头加载它,它很可能会工作。

In other words, you can't load it this way because http://infolab.stanford.edu/pub/papers/google.pdf doesn't let you do to so. When you will have it on your server and load it with proper response headers, it will most probably work.

有关此错误的更多信息,请参阅为什么我看到Access-Control-Allow-Origin不允许来源?错误在这里?

For more information about this error, refer to Why am I seeing an "origin is not allowed by Access-Control-Allow-Origin" error here?

如果你不托管这些文件,你可以通过代理管道它们(它可以是第三方应用程序或您的服务器)。例如,IvanŽužak,开发 urlreq - 在这种情况下完全符合我们需要的工具。

If you don't host these files, you can pipe them through a proxy (which can be a third-party app or your server). For example, Ivan Žužak, developed urlreq–a tool which does exactly what we need in this situation.

不使用直接链接到pdf文件,而是使用Ivan的代理网址:

Instead of using the direct link to pdf file, use Ivan's proxy url:


http:// urlreq.appspot.com/req?method=GET&url=http%3A%2F%2Finfolab.stanford.edu%2Fpub%2Fpapers%2Fgoogle.pdf

JSFIDDLE

这篇关于pdf.js是否只适用于某些pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆