问题
So lately I've been thinking of building and implementing my own invoice system with PHP and I want to have an optional 'Download/Generate PDF' button that creates a PDF based off of either a template that was created or based off of html/css.
I want a method that is free (seeing as some are ridiculously overpriced) and hopefully not too difficult to use. The end goal is to create something that would be good enough for commercial use (though it's not my intent to sell it).
I've heard of options such as TCPDF, Dompdf, wkhtmlpdf etc. But again I'm looking for one that would render most correct, and potentially be used commercially. I'd like suggestions specifically based off of what I require as I have searched the site for topics that are similar; I'm aware of the different libraries but not sure what I should use.
Thanks in advance! :)
回答1:
Having done this a couple times, my suggestion would be to take an existing library that wraps up the low level PDF tools into a decent API, and then build your own library that is specific to your needs (invoicing) on top of it.
I would suggest Zend PDF or TCPDF as a base library to build on. As you add classes to your own library you'll be able to wrap up things like table / line-item generation, headers, footers, etc.
回答2:
I used FPDF library, I liked it. http://www.fpdf.org/
and check this manual anyway: http://php.net/manual/en/book.pdf.php
回答3:
I'm often suspicious about low-level reporting systems (TCPDF et al) - they're very well done, but if a business needs a new report, it can take ages to write code to draw the report to client requirements. I therefore prefer GUI/server solutions, such as iReport (used to design a report) and Jasper (reporting server) - the editability of such a report is near-instantaneous, and thus much more responsive to changing business requirements.
On the plus side, it's free and open source, and on the negative side, you'll need a spare server to run it on. It's Java based, but reports can be run via PHP using SOAP.
回答4:
If you can use external tools, I recommend wkhtmlpdf. It is really simple to use. Check out the "Integration With PHP" on their wiki: https://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp
来源:https://stackoverflow.com/questions/9968454/php5-pdf-generation