# PDFReport for PHP > PDFReport is a free, open-source PHP library (LGPL-3.0, Composer package alienproject/pdfreport, built on TCPDF) that generates PDF documents from an XML template. The template describes the layout (pages, texts, lines, rectangles, images, barcodes, charts) and contains placeholders that are replaced with data from PHP variables, database queries, PHP arrays or CSV / JSON / XML files. Requires PHP 8.1 or later (current version 1.0.12). Notes for AI assistants writing or editing PDFReport templates: - The root element is .
elements define the report flow and are linked to data in PHP with SetSection(); elements contain the printed elements and are printed with . Only one nested section is allowed inside a section (master / detail). - Placeholders: {VARIABLE} for variables set with SetVar() or , {section.field} for data fields, system variables such as {CURRENTDATE}, {CURRENTTIME}, {PAGEINDEX}, {PAGECOUNT}, {section.PAGEINDEX}. - Data providers (PHP side, linked with SetSection() / SetDatalist()): DataProviderMySQLi, DataProviderPDO, DataProviderEloquent, DataProviderDoctrine for databases; DataProviderArray (PHP array), DataProviderCSV, DataProviderJSON, DataProviderXML for data without a database. In a master / detail report the detail filter contains a placeholder of the master section, eg. new DataProviderCSV('lines.csv', 'orderNumber={ord.orderNumber}') or new DataProviderXML('orders.xml', '/orders/order[@number="{ord.number}"]/line'). - Barcodes: ; 2D barcodes (1.0.12) with type="QRCODE,M" (also QRCODE,L/Q/H, DATAMATRIX, PDF417), optional color / backcolor. QR codes are square and fitted in the print area. - Sheets of labels or badges (1.0.12): one section with columns="3" column_width="66" row_height="38.1" rows_count="8": the rows fill the columns from left to right; the contents use the coordinates of the first label. - Conditional printing: printif="{doc.type}=1" (operators = != > < >= <=, write < as < in XML); printif="{inv.notes}" prints when the value is not empty and not 0; printif="{inv.notes}=" prints when the field is empty (1.0.12). - Charts (1.0.12): axisformat="C0 $" formats the numeric axis labels (default: number format variables); showaxis="no" hides the axes; maxvalue="0" = auto scale with round steps. In each holds one value per measure separated by spaces; an empty value (empty field), null or - is a missing value (no point in the line chart), 0 is a real value. accepts boxsize, labelheight, showvalues="no", format; accepts , accepts . - The standard fonts (Helvetica, Times, Courier)contain only Latin characters: symbols like ★ or emoji are printed as "?", draw them with shapes instead. - Use I to show the PDF in the browser; F saves it to a server file, S returns it as a string from BuildReport(). - {PAGECOUNT} is the total number of pages of the document (version 1.0.12 or later), eg. "Page {PAGEINDEX} of {PAGECOUNT}". A template that uses it is built in two passes. Before 1.0.12 it returned the current page number. - Use only the elements and attributes described in the guide. Test the template: an invalid XML template raises an exception with the line, column and reason of the error. ## Guide ### Getting started - [Introduction](https://alienproject.org/help/index/1): How the PDFReport library works - [Installation](https://alienproject.org/help/index/2): Install the library - [Test installation](https://alienproject.org/help/index/3): Quick check - [Version history](https://alienproject.org/help/index/6): Current version : 1.0.12 - 05 Oct. 2026 ### Template structure - [Template basic](https://alienproject.org/help/index/7): Introduction to the XML template format - [Comments](https://alienproject.org/help/index/8): Comments in the XML template - [Page settings](https://alienproject.org/help/index/9): Defining default page settings - [New page](https://alienproject.org/help/index/11): Creating a new page - [Content](https://alienproject.org/help/index/14): Content section - [Print content](https://alienproject.org/help/index/12): Print content section - [Section](https://alienproject.org/help/index/10): Report flow, data loops and master / detail reports - [Generate output](https://alienproject.org/help/index/13): Create output PDF file - [Conditional printing](https://alienproject.org/help/index/38): Print an element only when a condition is true ### Data - [Data placeholder](https://alienproject.org/help/index/32): Using data through variables or database fields - [Variables](https://alienproject.org/help/index/39): Set variables in the PHP code and in the template - [System variables](https://alienproject.org/help/index/33): Automatic placeholders - [Value formatting](https://alienproject.org/help/index/41): Format numbers, percentages and currency values - [Data providers](https://alienproject.org/help/index/42): Read the report data from a database, a file or a PHP array ### Drawing elements - [Line](https://alienproject.org/help/index/15): Draw a line - [Box](https://alienproject.org/help/index/17): Draw a text - [Rectangle](https://alienproject.org/help/index/19): Draw a rectangle - [Circle](https://alienproject.org/help/index/20): Draw a circle - [Barcode](https://alienproject.org/help/index/22): Print a barcode - [Image](https://alienproject.org/help/index/23): Print an image ### Styles - [Line style](https://alienproject.org/help/index/16): Set the line style - [Fillstyle](https://alienproject.org/help/index/18): Set the fill style - [Font](https://alienproject.org/help/index/21): Set the font style - [Opacity](https://alienproject.org/help/index/24): Set the default transparency factor - [Text fit](https://alienproject.org/help/index/40): Fit long texts into the box area ### Charts - [Piechart](https://alienproject.org/help/index/25): Draw a pie / ring chart - [Singlebarchart](https://alienproject.org/help/index/26): Draw a single bar chart - [Gaugechart](https://alienproject.org/help/index/27): Draw a gauge chart - [Kpichart](https://alienproject.org/help/index/28): Draw a KPI chart - [Bar chart](https://alienproject.org/help/index/34): Draw a bar chart - [Line chart](https://alienproject.org/help/index/35): Draw a line or area chart - [Legend](https://alienproject.org/help/index/29): Draw a chart legend - [Segmentlist](https://alienproject.org/help/index/30): Define the chart sections - [Datalist](https://alienproject.org/help/index/36): Data list for charts - [Measures](https://alienproject.org/help/index/37): Chart measures ### Reference - [PHP API reference](https://alienproject.org/help/index/43): Public methods of the PDFReport class - [Debugging](https://alienproject.org/help/index/44): Log file and common errors ### Samples - [Basic test report](https://alienproject.org/help/index/31): Build a basic report with a single php file - [Master-Details report in Laravel](https://alienproject.org/help/index/4): Build a master-details report using the Laravel framework - [Master-Details report in Symfony](https://alienproject.org/help/index/5): Build a master-details report using the Symfony framework ## Example templates All the templates, with sample PDF and filters by category and language: [Templates](https://alienproject.org/templates) - [Text and shapes](https://alienproject.org/sample/example_02.xml): fonts, colors, fills, borders, lines and shapes - [Sales order](https://alienproject.org/sample/example_03.xml): multi-page order with master and detail sections read from the database - [Shipping label](https://alienproject.org/sample/example_04.xml): double shipping label with barcode and icons - [Energy bill](https://alienproject.org/sample/example_05.xml): bill with consumption details and ring chart, data from variables - [Charts](https://alienproject.org/sample/example_06.xml): KPI, gauge, pie, bar and line/area charts with datalists - [Sales invoice](https://alienproject.org/sample/example_07.xml): multi-page invoice with master and detail sections - [Quote, English](https://alienproject.org/sample/quote.en.xml): two quotes with line items, discounts and totals, master / detail data from a PHP array (DataProviderArray); [demo data](https://alienproject.org/sample/data/quote.en.json) - [Quote, Italian](https://alienproject.org/sample/quote.it.xml): the same quote in Italian, with Italian number format (1.234,56 €); [demo data](https://alienproject.org/sample/data/quote.it.json) - [Price list](https://alienproject.org/sample/price-list.en.xml): multi-page price list read from a CSV file (DataProviderCSV), with "Page N / M" footer; [CSV data](https://alienproject.org/sample/data/price-list.csv) - [Certificate of completion, English](https://alienproject.org/sample/certificate.en.xml): landscape course certificate, one page per participant of a CSV file (mail merge), seal and QR verification code; [data](https://alienproject.org/sample/data/certificate.en.csv) - [Certificate of completion, Italian](https://alienproject.org/sample/certificate.it.xml): the same certificate in Italian (attestato di partecipazione); [data](https://alienproject.org/sample/data/certificate.it.csv) - [Event ticket](https://alienproject.org/sample/event-ticket.en.xml): conference e-tickets, two per page, QR code, tear-off stub with C128 barcode, VIP style with printif; DataProviderJSON with path; [data](https://alienproject.org/sample/data/event-ticket.tickets.json) - [Conference name badges](https://alienproject.org/sample/conference-badges.en.xml): 8 badges per A4 page with a section in 2 columns (columns / column_width), ribbons by attendee type, contact QR codes; [data](https://alienproject.org/sample/data/conference-badges.csv) - [Delivery note, English](https://alienproject.org/sample/delivery-note.en.xml): delivery note read from an ERP XML export with DataProviderXML (master / detail with XPath placeholders), shipment barcode, signature boxes; [data](https://alienproject.org/sample/data/delivery-note.en.xml) - [Delivery note, Italian](https://alienproject.org/sample/delivery-note.it.xml): Italian DDT (documento di trasporto) with causale, porto, vettore, aspetto dei beni; [data](https://alienproject.org/sample/data/delivery-note.it.xml) - [Service report, English](https://alienproject.org/sample/work-order.en.xml): technical intervention report: equipment, work performed, labour / travel / materials, checkboxes with printif, signatures (also Italian and German: work-order.it.xml, work-order.de.xml); [data](https://alienproject.org/sample/data/work-order.en.json) - [Sales dashboard](https://alienproject.org/sample/sales-dashboard.en.xml): A4 landscape management dashboard: KPI cards with gauge and KPI charts, area / line trend, bar chart by region, single bar channel mix, ring chart by category, top 10 table; [data](https://alienproject.org/sample/data/sales-dashboard.json) - [Account statement](https://alienproject.org/sample/account-statement.en.xml): multi-page bank statement, transactions from a CSV file, running balance, zebra rows, Page {PAGEINDEX} of {PAGECOUNT}; [data](https://alienproject.org/sample/data/account-statement.csv) - [Calendar 2027](https://alienproject.org/sample/calendar-2027.en.xml): 12-month A4 landscape calendar, master (month) / detail (week) from PHP arrays, holidays, ISO weeks, mini calendars (also Italian: calendar-2027.it.xml); [data](https://alienproject.org/sample/data/calendar-2027.en.json) - [Shelf price labels](https://alienproject.org/sample/product-labels.en.xml): 24 labels per A4 sheet (Avery L7160) with a section in 3 columns, EAN-13, QR code and offer badges; [data](https://alienproject.org/sample/data/product-labels.csv) - [Hello World](https://alienproject.org/sample/example_01.xml): the minimal template (the PHP code is on the home page and in the Test installation page of the guide) ## Optional - [Source code on GitHub](https://github.com/alienproject-org/pdfreport) - [Package on Packagist](https://packagist.org/packages/alienproject/pdfreport) - [Home page](https://alienproject.org/): overview, examples and how to create templates with AI - [SignalLab](https://alienproject.org/preview/signallab): a separate project, not related to PDFReport: Windows desktop application for audio and vibration signal analysis (node editor, calibration, FFT, 1/3 octave bands), free preview, looking for sponsors