如何编写 javascript 来加载网页并将其打印到图像文件并将该文件放在指定位置

发布于 2024-10-09 23:46:44 字数 288 浏览 0 评论 0原文

这就是我想要做的:

  1. 从特定的加载网页 location
  2. 将该网页打印为 jpeg, png 或其他图形文件格式
  3. 将该图像上传到另一个网站, 或将其保存到我本地的某个位置 我知道

window.print(),但它似乎总是打开一个打印窗口,我想尽可能默默地完成此操作。

本质上,我希望能够拍摄网页快照,以便将其放入由其中一个电子相框访问的目录中。他们可以访问基于 Web 的服务,也可以访问本地网络上的目录。

预先感谢您的帮助, 雷本

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 service, or a directory on the local network.

Thanks in advance for your help,
Rben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

早茶月光 2024-10-16 23:46:45

浏览器不会让您“静默”打印,因为如果他们这样做,各地的网站都会使用它们让您的打印机因垃圾邮件而超载。没有办法解决这个问题(如果你找到了,他们会尽快关闭它)。

因此,您可以a)创建一个浏览器插件或类似的东西,让您脱离浏览器的“沙箱”,或者b)编写一个获取网页的网络爬虫应用程序,并找到一些其他技术将其呈现为图像(也许以编程方式驱动浏览器)。

如果其中任何一个听起来很有希望,请告诉我,我可以填写有关如何进行这些操作的更多详细信息。

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.

守望孤独 2024-10-16 23:46:45

你不能使用 JavaScript 来做到这一点。 wkhtmltopdf 可以帮助您。以下是 SO讨论中可用于执行此操作的工具列表。

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.

兔小萌 2024-10-16 23:46:45

我整理了一个脚本,我认为这可能正是您所寻找的...屏幕截图演示

它使用 printElement 和 Feedback.js(不记得来源)并且它允许您可以截取整个网页并将其作为电子邮件发送或发送到打印机。

让我知道这是否有帮助,抱歉,我没有在页面上提供更多详细信息,但我现在正在工作,哈哈

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文