PHP create PDF invoice

There are several libraries available in PHP that can be used to create PDF invoices, such as TCPDF and FPDF.

TCPDF is a PHP class for generating PDF documents without requiring external extensions. It supports a wide range of page formats and custom page margins, as well as support for UTF-8 Unicode, RTL languages, and barcode generation.

Watch a course Learn object oriented PHP

FPDF is another popular PHP library for creating PDFs. It allows you to create PDFs by directly writing text and graphics to the document, and supports multiple languages and encodings.

Both libraries are open-source and can be easily integrated into any PHP application.

Here is an example of how to create a PDF invoice using TCPDF:

<?php
require_once 'tcpdf_include.php';

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Company');
$pdf->SetTitle('Invoice');

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

$pdf->AddPage();

$pdf->SetFont('helvetica', '', 12);

$html = '<table>';
$html .= '<tr><td>Invoice #:</td><td>12345</td></tr>';
$html .= '<tr><td>Customer:</td><td>John Doe</td></tr>';
$html .= '</table>';

$pdf->writeHTML($html, true, false, true, false, '');

$pdf->Output('invoice.pdf', 'I');

?>

This is a simple example, you can customize it according to your requirement.