PHP create PDF invoice PHP create PDF invoice php php

PHP create PDF invoice


I would recommend creating an html / css representation of what you want a PDF of and using that to generate the PDF. There are dozens of applications to handle the conversion, and there is a good thread with a lot of answers here: Convert HTML + CSS to PDF with PHP?


I use TCPDF (see http://www.tcpdf.org/) for this: its pretty capable and not too painful to get setup. I will say that depending on your data source you may have some issues. In my case my data is sourced from a SOAP interface to my accounting system and use CodeIgniter for my app, and I can do this:

$address = $extraclient->get_company_address();// generate the PDF invoice$this->load->library('pdfinvoice');// set document information$this->pdfinvoice->SetSubject("Invoice " . $data_invoice['code_invoice']);// add a page$this->pdfinvoice->AddPage();$this->pdfinvoice->StartPageOffset();// write the client's details out$width = $this->pdfinvoice->GetPageWidth()/2;$margins = $this->pdfinvoice->getMargins();$this->pdfinvoice->SetFont('times', 'b', $this->pdfinvoice->bigFont );$this->_row($width, array("From:", "To:"));$this->pdfinvoice->SetFont('times', 'i', $this->pdfinvoice->smallFont );$this->_row($width, array("MY NAME", $customer['name_contact']));$this->_row($width, array($address['phone'], $customer['name_customer']));$this->_row($width, array($address['street'], $customer['address1_street']));$this->_row($width, array($address['city']. ", ".$address['state']." ".$address['zipcode'],                          $customer['address1_city']. ", ".$customer['address1_state']." ".$customer['address1_zip

The full code is quite frankly too long to insert here, but you should get the idea, and you get fairly precise layout control.


You may wanna look at html2Pdf. It is a php class based on FPDF and it allows you to create PDF file from HTML. So just format your text using html and then create its pdf. Its very flexible and give greate control.

SourceForge Link