Documentation index
Quickstart
This is a small guide to help you setup PDML2 and get started creating your first PDF document. Pdml2 can be used both from the command line and a web browser.
Setup:
(This assumes you already have php installed and working on your system.)
- Unzip pdml2 in a directory PHP looks up. For quick testing, you can unzip it in a sub-directory of your web server, and any php files in that directory should be able to use it.
- You should now see "pdml2.php", "fpdf.php" and a "fonts" sub-directory in the directory you picked.
- Create a new php file in that directory, for example "test.php"
- The first line of a PDML2 document needs to be: <?php include "pdml2.php; ?>
- Following this, you can write a normal PDML document (see syntax below for further information.
- Save your file, and load it in your browser or start it with your command line php.
Note that you can use php tags freely within your PDML document. It is recommended however to split your PDML templates from your PHP code, linking them with simple PHP calls in your templates. The best way to do this is to use a template engine, like Smarty.
You should now be ready to jump to the documentation.
Example 1
Save the below two files in the pdml2 directory. Open/run example1.php with your web browser or the PHP command line interpretor.
Template file
<!-- Save this file as example1.pdml --> <pdml> <header> <title>Hello PDML</title> </header> <body> Hello world! </body> </pdml>
PHP file
<?php // Save this file as example1.php include ("pdml.php"); $tpl = file_get_contents("example1.pdml"); $pdml = new PDML("P","pt","A4"); $pdml->ParsePDML($tpl); $s = $pdml->Output("example1.pdf","F"); ?>
Supported units for sizing
The default unit for all lengths and sizes are in points. You can override this by specifying a unit after the number. Top and Left distances are relative to the top-left corner of the page, that is known as 0,0.
Supported units are:
- mm: millimeters
- cm: centimeters
- in: inches
- pt: points. equivalent to not specifying a unit.
- %: percentage. For length, this is the percentage of the appropriate page dimension. For font size, this is relative to the current font size.
Supported colors
The default color for text is black and the default color for background is white. You can override this by specifying a color and fillcolor in some of the other tags, e.g. the <cell> tag.
Colors are specified as a group of 3 hexadecimal numbers, e.g. '#a1b2c3'. The first group define the amount of red, the next green and the last blue.
#000000 = black
#ffffff = white
#ff0000 = red
#00ff00 = green
#0000ff = blue
There are plenty of information on these colors on the internet. You can find a color table here.