使用无头浏览器Phantomjs打开PDF [英] Open PDF with headless browser Phantomjs

查看:182
本文介绍了使用无头浏览器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.

这篇关于使用无头浏览器Phantomjs打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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