Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP create PDF invoice

Hi does anyone know how I can create a nicely formatted PDF invoice through PHP?

Ideally I'm looking for something with a header and then an itemised listing of the products with some sort of table around. After a quick Google I would be comfortable with generating a PDF but to try and style it nicely would be another thing altogether.

Thanks

like image 834
Martin Avatar asked May 06 '11 17:05

Martin


People also ask

How do I create an Fpdf invoice?

First we download the FPDF zip file from the http://www.fpdf.org/ and upload it on server at root directory. Then set the PDF generator button at your page as per your requirement. In this case we set the invoice button at order history information for particular order to generate invoice for particular order.


2 Answers

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?

like image 179
Timothy Strimple Avatar answered Sep 28 '22 17:09

Timothy Strimple


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.

like image 22
Femi Avatar answered Sep 28 '22 18:09

Femi