开发者

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 (i.e., 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜