简体   繁体   English

按计划将html页面打印为PDF

[英]print html page to PDF on a schedule

I have a HTML page that uses javascript to generate dynamic images using a graph handler on a different server. 我有一个HTML页面,该页面使用javascript在其他服务器上使用图形处理程序生成动态图像。 The images will contain the same data for 1 week but will change when the 1 week window expires. 图像在1周内将包含相同的数据,但在1周窗口期满时将更改。

I am trying to come up with a way to automatically save the contents of the page to either a local file on the server or write to a PDF file. 我正在尝试提出一种自动将页面内容保存到服务器上的本地文件或写入PDF文件的方法。

I tried to use a 'web downloader' like HTTTrack, but it does not get the dynamic images... 我试图使用像HTTTrack这样的“网络下载器”,但没有获得动态图像...

I am running the html page off IIS. 我正在从IIS运行html页面。

I have no experience with IIS or ASP. 我没有IIS或ASP的经验。

Thanks! 谢谢!

I'm not sure that I see any way to do this directly off the front end in an automatic manner. 我不确定是否有任何方法可以直接在前端直接进行自动操作。 The challenge is that any "screen scraper" you have go out and grab the site with would need to be running javascript to get the tables, which isn't how I see many such systems operating. 面临的挑战是,您出去使用网站抓取的任何“屏幕抓取工具”都需要运行javascript来获取表格,而这并不是我看到的许多此类系统运行的方式。 It's partially why you see strangeness on Archive.org when you have a site that's heavily augmented with javascript or flash. 这就是为什么当您的网站上大量添加了JavaScript或Flash时,您在Archive.org上看到陌生的原因。

An untested concept you might attempt was posted in this Stack Question 您可能尝试使用的未经测试的概念已发布在此堆栈问题中

I could see some sort of a system that you rig together with another computer that schedules an browser load then prints to .pdf in some fashion. 我可以看到您将某种系统与另一台计算机绑定在一起,该计算机计划浏览器的加载,然后以某种方式打印为.pdf。 I've been unable to find any specific software that would automate that process, so you'd be left cobbling such a system together on your own. 我一直找不到能使该过程自动化的任何特定软件,因此您将不得不自己将这种系统整合在一起。

Clearly you have the data available to make your dynamic images. 显然,您拥有可用于制作动态图像的数据。 The most feature-rich way I could think of would be to use a system like Jasper Reports or Crystal Reports, which you could feed your data, replicate the report, and easily output via pdf, a built-in export in both systems. 我能想到的功能最丰富的方法是使用Jasper Reports或Crystal Reports之类的系统,您可以输入数据,复制报告,并通过pdf(这两个系统中的内置导出)轻松输出。

Perhaps its worth questioning your end purpose. 也许值得质疑您的最终目的。 To me, creating a "snapshot" of the relevant data in another table and using another system to render your graphs from that snapshot data seems far more valuable than just a print of the screen. 对我来说,在另一个表中创建相关数据的“快照”并使用另一个系统从该快照数据中呈现图形似乎比仅打印屏幕更有价值。 You can then go back and adjust data as needed, or use it for other reporting purposes, exporting in any number of tools that are even as simple as Access. 然后,您可以返回并根据需要调整数据,或将其用于其他报告目的,并使用甚至与Access一样简单的任何工具导出。 Heck, 10 years down the road you may want the data to look better than the graph system you're currently using, and you'd have the data to render it any way you want. 哎呀,在未来的10年中,您可能希望数据看起来比当前使用的图形系统更好,并且您将有数据以任意方式呈现它。 When the VP of marketing comes looking for his numbers, a simple click would output those numbers that could be manipulated as needed from there. 当营销副总裁来寻找他的数字时,只需单击一下,就会输出那些数字,可以从那里根据需要进行操作。

I was able to accomplish what I wanted to do using wkhtmltopdf to convert my HTML page with Javascript to PDF. 使用wkhtmltopdf将带有Javascript的HTML页面转换为PDF,就可以完成我想做的事情。 I ran the job via a task scheduler to supply my website url and output file name as parameters. 我通过任务计划程序运行该作业,以提供我的网站URL和输出文件名作为参数。

I then used a windows batch file to check if the file was created and then rename/email it to interested parties. 然后,我使用Windows批处理文件检查该文件是否已创建,然后将其重命名/通过电子邮件发送给感兴趣的各方。

This of course requires that you have the ability to install wkhtmltopdf on your server. 当然,这要求您具有在服务器上安装wkhtmltopdf的能力。

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

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