The PDF architecture is currently the best acclimated architecture to barter documents. If you accommodate your website users with printable versions of invoices, accident tickets and added agnate documents, you’ll best acceptable appetite to accomplish them as PDFs on the fly. In this commodity you will see how you can use Zend_Pdf to auto-generate PDF invoices.
Zend_Pdf allows you to actualize new PDF abstracts or amount absolute ones and adapt them. While creating a new certificate isn’t that difficult, it makes added faculty to actualize a arrangement of the balance with the advice that doesn’t change (company name, address, logo, etc.). It’s bigger to architecture your balance in a affairs like Microsoft Word or LibreOffice Writer and consign it as a PDF. Again you can amend the PDF with Zend_Pdf with chump and transaction-specific information. You’ll save coding time because you don’t accept to position every element, and it will booty beneath time for the PDF to be generated.
This is what the balance arrangement I will be application in this commodity looks like. Your balance can attending altered depending on your needs, but the concepts in this commodity will abide the same.
If this is the aboriginal time you’re application Zend Framework, download the latest adaptation from www.zendframework.com, upload and ameliorate the aeroembolism book on your server, and use the afterward curve at the top of your calligraphy to configure the chic autoloader. The autoloader will let you actualize new altar after accepting to absolutely accommodate all the appropriate files in your code.
Remember to change the amount of the ZF_PATH connected to the aisle area you uploaded the archetype of the Zend Framework library.
Editor Note Oct 14 2012: The accompanying cipher on GitHub has been adapted to use Composer for installing Zend Framework. As ZF2 is not backwards accordant with ZF1, the adaptation has been bound at 1.11.11. Please accredit to the cipher for acceptable ZF_PATH.
Zend_Pdf allows you to amount an absolute PDF certificate with the changeless load() method.
The load() adjustment reads the book at the accustomed aisle and allotment an instance of a Zend_Pdf commodity which manages aggregate accompanying to the PDF.
Zend_Pdf represents anniversary folio of the PDF as instances of the Zend_Pdf_Page object. Its accessible acreage pages is an arrangement of the altar in the aforementioned adjustment the pages are begin in the document. You can account from this behavior if you accept a PDF certificate with abounding pages and you appetite to alter its pages; whichever adjustment the Zend_Pdf_Page altar are in the pages array, that is the adjustment the pages will be rendered in the final document.
When you address argument to the PDF page, you are absolutely cartoon shapes that looks like text, and these shapes are authentic by the called font. So afore writing/drawing text, you charge specify which chantry you appetite to use. The Zend_Pdf_Font chic is acclimated to actualize a chantry ability which you again use to specify the chantry acclimated back agreement text.
There are two means to amount a font. The aboriginal is to use the changeless adjustment fontWithName() and accommodate one of the afterward constants that represent the 14 accepted fonts that all PDF admirers support:
The additional way is to accommodate the aisle to the chantry book that resides on your book arrangement to the changeless adjustment fontWithPath(). Make abiding that the chantry is a TrueType chantry or abroad fontWithPath() will bandy a Zend_Pdf_Exception.
The chantry ability is again anesthetized to the Zend_Pdf_Page‘s setFont() instance adjustment as the aboriginal parameter, and the chantry admeasurement abstinent in credibility as the additional constant (1 point = 1/72 inches). The represented chantry will again be acclimated whenever argument is fatigued to that page.
It’s not binding to set a blush for argument afore cartoon it; atramentous will be acclimated by absence if none is specified. But if do you appetite to use a assertive color, you can specify one with one of the Zend_Pdf_Color* objects. Zend_Pdf supports three altered blush spaces; you can use Gray Scale, RGB, or CMYK. Also, you can specify colors application HTML-style notation.
The blush is again anesthetized to the setFillColor() adjustment of the Zend_Pdf_Page instance.
Drawing argument on a folio is done application Zend_Pdf_Page‘s drawText() instance method. It takes a cord of text, and the X and Y coordinates area you appetite the argument to be placed. The coordinates are abstinent in points, and the agent 0,0 is placed at the bottom-left bend of the page. An accretion X amount moves the position appear the right, and an accretion Y amount moves the position up.
Typically you’ll retrieve and account advice to put on the balance from a database, but for the account of archetype I’ve appear up with the following:
The trickiest allotment is award the actual area to abode the argument on the folio and you may crave some balloon and absurdity alike if you’ve anxiously abstinent your distances. The acceptable account is that back the arrangement elements are static, already you apperceive what coordinates to use they won’t change.
After abacus the advice to the template, you can either save it to a altered book (be accurate not to overwrite your template!) or accelerate it to the browser. To save it, you use Zend_Pdf‘s instance adjustment save().
Using the instance adjustment render() will acknowledgment the PDF certificate as a string. This is apparently what you appetite if you are breeding a certificate on the fly and appetite the user to download it after extenuative archetype of the certificate on your server first. You can achievement the actual HTTP headers so the browser will apperceive how to handle the file, and again accelerate the certificate string.
Now you apperceive the basics of application Zend_PDF to actualize PDF documents, admitting there are still abounding added appearance accessible than the ones I’ve mentioned in this article. The antecedent cipher for this commodity is accessible on GitHub if you’d like to carbon it and experiment. And of course, feel chargeless to leave comments with any problems you encounter.
Image via Christina DeRidder / Shutterstock
Invoice Pdf Php – invoice pdf php
| Delightful in order to my own website, with this time I am going to teach you about keyword. And today, this can be a very first image: