简体   繁体   English

从php将远程网页打印为pdf

[英]Print a remote web page to pdf from php

I read a lot of topics about scripts that compute html and output pdf; 我阅读了很多有关计算html和输出pdf的脚本的主题。 I tried lots of them, and I am always disapointed in the results. 我尝试了很多,但结果总是令我失望。 Lots of them don't consider the external CSS, lots of them can't be executed from shared hosting (need to be installed in some unaccessible places, like DOMPDF), etc. Also, lots of the threads on the question are pretty old (most of them've been asked in 2010). 他们中的许多人没有考虑外部CSS,其中许多人无法从共享托管中执行(需要安装在某些不可访问的地方,例如DOMPDF),等等。而且,这个问题上的许多线程都已经很老了(其中大多数已在2010年被问到)。

Question: Is there a simple way to cURL (from a php script) a remote web page and simply save a pdf of the "print" (like in css media print) version of the page, or even a jpeg, or a docx, or anything that "contains" the images and the styling for offline viewing? 问题:是否有一种简单的方法来(从php脚本中)访问远程网页,并简单地保存页面的“打印”(如css媒体打印)版本的pdf,甚至是jpeg或docx,或“包含”图像和样式以供离线查看的任何内容? And more important, can it be free/open source? 更重要的是,它可以免费/开源吗?

All the web browsers do that with no effort. 所有的网络浏览器都毫不费力地做到了这一点。 Once on the page, only press ctrl-p and there it goes (almost). 进入页面后,仅按ctrl-p即可到达(几乎)。 Why is it so trivial to find a good script that can do this? 为什么找到可以做到这一点的好脚本如此琐碎? Is there a way to emulate a browser, or what...? 有没有办法模拟浏览器,还是什么?

Isn't it possible to cURL and force css media print, then take a snapshot of this? 可能无法cURL并强制CSS媒体打印,然后对此进行快照吗?

The difficulty to find this seems very strange to me... I feel like it's a quite simple task. 很难找到这个对我来说似乎很奇怪……我觉得这是一个非常简单的任务。

Try to call wkhtmltox from PHP. 尝试从PHP调用wkhtmltox。

wkhtmltox/bin/wkhtmltopdf www.stackoverflow.com stackoverflow.pdf

This PHP library seems to work with wkhtmltox: http://thejoyofcoding.org/php-wkhtmltox/ 这个PHP库似乎可以与wkhtmltox一起使用: http ://thejoyofcoding.org/php-wkhtmltox/

This might help: http://davidbomba.com/php-wkhtmltox/ 这可能会有所帮助: http : //davidbomba.com/php-wkhtmltox/

在此处输入图片说明

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

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