[英]Create pdf from html and php
I have researched this question on stackoverflow, but I'm confused by the answers.我已经在 stackoverflow 上研究过这个问题,但我对答案感到困惑。 I've created an application in php that produces a report.
我在 php 中创建了一个生成报告的应用程序。 I'd like for the report to be created as a pdf on a button push.
我希望通过按下按钮将报告创建为 pdf。
Using google chrome and firefox manually to 'file>print as pdf' renders the text of the report generated by my php script, but doesn't produce any of the colours.手动使用 google chrome 和 firefox 'file>print as pdf' 呈现由我的 php 脚本生成的报告文本,但不产生任何颜色。
Is there a relatively simple way to do this without apis, to take exactly what appears in the browser, and create a pdf of it?是否有一种相对简单的方法可以在没有 api 的情况下执行此操作,准确获取浏览器中显示的内容,并创建它的 pdf? If there is, could somebody please tell me how?
如果有,有人可以告诉我怎么做吗?
Thank you.谢谢你。
If you have time to look at server side stuff, check out phantomjs , can generate a PDF from html in one line using the rasterize.js example:如果您有时间查看服务器端的内容,请查看phantomjs ,可以使用 rasterize.js 示例在一行中从 html 生成 PDF:
eg例如
phantomjs rasterize.js index.html index.pdf A4
I normally create the HTML using PHP and then use php to execute phantomjs with exec() .我通常使用 PHP 创建 HTML,然后使用 php 使用exec()执行 phantomjs。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.