简体   繁体   中英

How to render a dynamic HTML/PHP page in a PDF programmatically

I've got a PHP page that I generate, forming an expense report for clients. I've found that the clients end up file->saving the output, emailing it around, and printing it. Since emailing HTML and PHP isn't really ideal (ie, images are lost, formatting is wonky), I'd like to render the page to a pdf and stream that to them.

Now, I've thought of good ol' "Print as PDF," but not all clients have that ability. I've looked into doing it myself with PHP PDFLib, but that gets pretty hairy. I've looked into DOMPDF and DocRaptor, but they attempt to parse the DOM and generate a pdf, which doesn't work well for more complex designs.

Here's the tantalizing thing: I use a Mac, and print->preview on the Mac does exactly what I want. It takes the pixels of the rendered page and generates a pdf out of it. If only I could harness that power! Is there a way? What can I do?

This library seems to have the right ingredients: http://www.rustyparts.com/pdf.php

1) I never used it though, so can't tell much about it ( cUrl -> html2ps -> ps2pdf )

2) Also maybe it will be easier to write a shell script ( cUrl, html2ps, ps2pdf ), and execute it in php, if it's an option (though not the best practice - security-wise)

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