Open PDF with headless browser Phantomjs

空扰寡人 提交于 2019-12-08 13:11:18

问题


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()

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?


回答1:


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.

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



来源:https://stackoverflow.com/questions/37082485/open-pdf-with-headless-browser-phantomjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!