简体   繁体   English

使用无头浏览器Phantomjs打开PDF

[英]Open PDF with headless browser Phantomjs

I have a pdf that is hosted on an s3 server, I would like to open the pdf and take screenshots within phantomjs. 我有一个托管在s3服务器上的pdf文件,我想打开pdf文件并在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()

I searched the docs but found nothing regarding opening a pdf. 我搜索了文档,但未找到有关打开pdf的信息。 My ultimate goal is to screenshot the pdf and injecting an overlay image with jquery. 我的最终目标是截图pdf并使用jquery注入叠加图像。 Is this possible using only phantomjs and jquery? 仅使用phantomjs和jquery可以做到这一点吗?

PDF file is not a webpage, so naturally PhantomJS will not render it. PDF文件不是网页,因此PhantomJS自然不会呈现它。 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 . 但是,有些项目和服务可以在浏览器中呈现PDF,例如Mozilla的pdf.js或Google的在线PDF查看器

Since those produce valid HTML, you could work with them in PhantomJS. 由于它们产生有效的HTML,因此您可以在PhantomJS中使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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