简体   繁体   中英

Create pdf from html and php

I have researched this question on stackoverflow, but I'm confused by the answers. I've created an application in php that produces a report. I'd like for the report to be created as a pdf on a button push.

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.

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? 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:

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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