On line guide/help
Navigate sequentially through the guide pages or search for a topic of interest to you
Start Prev. NextIntroduction
How the PDFReport library works
The library uses an XML template that describes the structure of the PDF document (for example, page size and orientation, objects to display: text, lines, rectangles, barcodes, graphics, etc.) and the data to print (via placeholders that are automatically replaced with the data).
PHP code
For very simple reports, you can create a PHP report with just 5 lines of code, as the following example:
<?php
use AlienProject\PDFReport\PDFReport;
$report = new PDFReport();
$report->LoadTemplate('demo.xml');
$report->SetVar('MESSAGE', 'Current date ' . date('Y-m-d'));
$report->BuildReport();
?>
PHP sample code
PHP code explanation:
- Use the "use" statement to automatically load the PDFReport class
- Create a new library instance
- Pass the XML template to the instance (using LoadTemplate or SetTemplate method)
- Define the data sources (external, such as data connectors linked to databases/files, or via variables using SetVar method)
- Generate the report using the "BuildReport" method
The PHP code load the following XML template file. The XML template code does not necessarily need to be stored in a file. The XML template could for example be stored in a text field of a database. This way, for example, the end user could choose the template to use, or advanced design users could focus on the template to customize it according to their needs at the time.
<pdf>
<!-- *** Document info. *** -->
<info>
<creator>Alien Project</creator>
<author>#MBR</author>
<title>Hello World</title>
</info>
<section id="main">
<!-- Create a new page with the following settings when this section starts -->
<page format="A5" orientation="L"/>
<!-- Print content -->
<print_content>hello</print_content>
<!-- save to file -->
<output>
<dest>F</dest>
<name>page_sample_01.pdf</name>
<isUTF8>true</isUTF8>
</output>
</section>
<content id="hello">
<!-- *** Print a single box : start *** -->
<box x1="10" y1="60" x2="200" y2="85">
<text>{HELLO_MESSAGE}</text>
<textvertalign>Center</textvertalign>
<texthorizalign>Center</texthorizalign>
<border>0</border>
<linewidth>0.25</linewidth>
<linecolor>000000</linecolor>
<fill type="S" color="2874a6"/>
<font>
<fontfamily>Helvetica</fontfamily>
<fontsize>32</fontsize>
<fontstyle>B</fontstyle>
<fontcolor>FFFFFF</fontcolor>
</font>
</box>
<!-- *** Print box : end *** -->
</content>
</pdf>
File : demo.xml
Once the data sources (e.g. a MySQL view) have been defined, changes to the report are usually made only in the XML template and/or the data view.