开发者

How can I write javascript that will load and print a web page to an image file and put that file in a specified location

开发者 https://www.devze.com 2023-02-01 17:19 出处:网络
Here\'s what I want to do: Load a web page from a specific location Print that web page into a jpeg, png, or other graphic file format

Here's what I want to do:

  1. Load a web page from a specific location
  2. Print that web page into a jpeg, png, or other graphic file format
  3. Upload that image to another site, or save it to a location on my local network

I know about window.print(), but that always seems to open up a print window, and I'd like to do as much of this operation silently as possible.

Essentially, I want to be able to take a snap shot of the web page so it can be put in a directory that is accessed by one of those electronic picture frames. They can either access a web-based se开发者_如何学JAVArvice, or a directory on the local network.

Thanks in advance for your help, Rben


Browsers will not let you print "silently", because if they did websites all over the place would use them to overload your printer with spam. There's no way around it (and if you found one, they'd close it as quickly as they could).

So, you could either a) create a browser plugin or something similar that gets you outside the broswer's "sandbox", OR, b) write a web crawler app that obtains the web page, and find some other technique to render it into an image (drive a browser programmatically perhaps).

If either of those sounds promising, let me know and I can fill in more detail on how to go about them.


You can't do that using javascript. wkhtmltopdf can help you. Here are the list of tools available to do it in this SO discussion.


I put together a script i think might be just what your looking for... Screenshot Demo.

It uses printElement and Feedback.js(Can't remember the source) and it allows you to screenshot the whole webpage and either send it as an email or to a printer.

Let me know if this helps and sorry i have no put more detail about it on the page but I am at work at the moment lol

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号