使用无头浏览器Phantomjs打开PDF

使用无头浏览器Phantomjs打开PDF

问题描述:

我有一个托管在s3服务器上的pdf,我想打开pdf并在phantomjs中截取屏幕截图。每当我得到失败的状态。我环顾四周,似乎无法找到一个简单的解决方案

I have a pdf that is hosted on an s3 server, I would like to open the pdf and take screenshots within phantomjs. Everytime I get a status of fail. I looked around and cannot seem to find an easy solution

var page = require('webpage').create();
var link = 'http://vfs.velma.com/Velma/testcard.pdf'; 
page.open(link, function(status) {
if (status!=='success') {
    console.log(status);
    phantom.exit();
} 
console.log(status);
phantom.exit();
});//ends page open()

我搜索了文档但没有找到关于打开pdf的内容。我的最终目标是截取pdf并使用jquery注入叠加图像。这可能只使用phantomjs和jquery吗?

I searched the docs but found nothing regarding opening a pdf. My ultimate goal is to screenshot the pdf and injecting an overlay image with jquery. Is this possible using only phantomjs and jquery?

PDF文件不是网页,所以PhantomJS自然不会渲染它。但是,有些项目和服务可以在浏览器中呈现PDF,例如Mozilla的 pdf.js 或Google的在线PDF查看器

PDF file is not a webpage, so naturally PhantomJS will not render it. However there are projects and services that make possible rendering PDF in a browser, like Mozilla's pdf.js or Google's online PDF viewer.

由于那些生成有效的HTML,您可以在PhantomJS中使用它们。

Since those produce valid HTML, you could work with them in PhantomJS.