Content
- the pdfTag class
- how to use pdfTag
- common elements
- miscellaneous elements
- text elements
- graphic elements
- hypertext elements
- index
Creating pdfs with pdfTag is quiet easy as creating webpages.
First of all you need a XML source. Here is an example:
Listing 1: xml source 'sample.xml'
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<page format="A4">
<setfont font="Helvetica" size="12.0"/>
<showxy x="100" y="100">Test</showxy>
</page>
</document>
Create a file with the content from listing 1 and name it 'sample.xml'
The next step will be the php script, which creates the pdf.
Listing 2: 'pdf.php'
<?php
include("pdfTag.php");
$pdf = new pdfTag();
$pdf->readFromFile('sample.xml');
if(!$_REQUEST["show"]):
$pdf->Debug = true;
$pdf->pdfProfile = true;
$pdf->generatePDF();
?>
<a href="pdf.php?show">click to view the pdf</a>
<?php
else:
$pdf->generatePDF();
$pdf->dumpPDF();
endif;
?>
We use the properties 'Debug' and 'pdfProfile' of the instatiated object for some informational
output.
$pdf->generatePDF() parses the xml source and create the pdf, per default memory. With
$pdf->dumpPDF() the generated pdf will be passed to the client, i.e. a browser. Be sure that no other
output from your script is send to the client before, otherwise the pdf can't be displayed or downloaded
by the client without errors.
document
Syntax: <document [author] [creator] [keywords] [subject] [title] >..<document>
Attributes:
- author="string"
- creator="string"
- keywords="string"
- subject="string"
-
title="string"
These attributes set possible values for information about the document, all of them are optional.
<document author="Roy Kaldung" creator="pdfTag/PHP">
..
<document>
page
Syntax: <page (width height)|format [orientation]>..</page>
Attributes:
- width="double"
- height="double"
- format="string"
For an easy page definition the are some predefined formats:- A4/DIN A4
- A5/DIN A5
- A6/DIN A6
- letter
- legal
- ledger
- 11x17
- orientation="portrait|landscape"
<page format="A4" orientation="landscape">..</page>
addthumbnail
Syntax: <addthumbnail id />
Attributes:
-
id="string"
Adding a thumbnail to the current page. Before adding it, you must load it with openimagefile. The image is referenced by the attribute 'id'. Using an undefined id results in a warning.
<addthumbnail id="thumb1"/>
See also:
openimagefile
annotation
Syntax: <annotation llx lly urx ury title text />
Alternative: <annotation llx lly urx ury title>text</annotation>
Attributes:
- llx="double"
- lly="double"
- urx="double"
- ury="double"
- title="string"
- text="string"
Adds an annotation to the current page, at the position llx,lly (lower left x and y) and urx,ury (upper right x and y) with a title and the mentioned attribute text as the content.
<annotation llx="0" lly="0" urx="100" ury="100" title="Annotation" text="This is my annotation"/>
border_color
Syntax: <border_color colors/>
Alternative: <border_color>colors</border_color>
Attributes:
- colors="r,g,b"
set the actual color for all drawed borders to the specified values.
<border_color colors="0,0,1"/>
<-- set the border color to blue -->
initgraphics
Syntax:
<initgraphics />
Attributes:
- none
This elements will reset all color and graphic state paremeters to their defaults.
<initgraphics />
openimagefile
Syntax: <openimagefile id type src />
Attributes:
- id="string"
- type="[tiff|png|gif|jpeg]"
-
src="string"
This tag make the image, specified by src, available for using in the whole document. All three attributes must be present, see the documentation of the pdflib for further information about the size of the image.
<openimagefile id="thumb" type="tiff" src="img/Thumb.tiff"/>
See also:
addthumbnail
outline
Syntax: <outline [id] text [parent] [open]/>
Alternative: <outline [id] [parent] [open]>text</outline>
Attributes:
- text="string"
- id=string
- parent="string"
-
open="open|close"
The content of text will be added as a outline to the current page. If parent is specified it must be an existing id of another outline. If the value of open is 'open' the outline will be displayed.
<outline id="chapter1" open="open" parent="content"/>
placeimage
Syntax: <placeimage id x y [scale] />
Attributes:
- id="string"
- x="double"
- y="double"
- scale="double"
Places an image, already loaded with openimagefile, to the position 'x','y'. The image is referenced by 'id'. If 'scale' is specified, it it scaled. The default scale is set to '1.0'.
<placeimage x="100" y="100" id="img1" />
See also:
openimagefile
arc
Syntax: <arc x y radius start end />
Attributes:
- x="double"
- y="double"
- radius="double"
- start="double"
- end="double"
The element 'arc' draws an circular arc with the center 'x','y' and radius 'radius', starting with angle 'start', ending with angle 'end'.
<arc x="200" y="150" radius="30" start="0" end="90" />
circle
Syntax: <circle x y radius />
Attributes:
- x="double"
- y="double"
- radius="double" Draws a circle with the center 'x', 'y' and the radius 'radius'.
<circle x="200" y="150" radius="30" />
line
Syntax: <line x1 y1 x2 y2/>
Alternative: <line>x1,y1,x2,y2</line>
Attributes:
- x1="double"
- y1="double"
- x2="double"
- y2="double"
- linewidth="double", optional
<line linewidth="0.3">100,75,300,250</line>
weblink
Syntax: <weblink llx lly urx ury url />
Attributes:
- llx="double"
- lly="double"
- urx="double"
- ury="double"
- url="string"
Draws a rectangle with the coordinates llx, lly, urx, ury and open a link to the url 'url' if the user click on it.
<weblink llx="50" lly="650" urx="200" ury="670" url="http://www.kaldung.de/pdftag" />
addthumbnail (element)
annotation (element)
arc (element)
author (attribute)
document
border_color (element)
circle (element)
clip (element)
close (value of attribute)
outline
closepath (element)
colors (attribute)
border_color (element)
continue_text (element)
creator (attribute)
document
curveto (element)
dash (element)
document (element)
dumpPDF() (method)
duration (element)
fill (element)
fill_stroke (element)
format (attribute)
page
generatePDF() (method)
height (attribute)
page
id (attribute)
addthumbnail
openimagefile
outline
placeimage
initgraphics (element)
keywords (attribute)
document
landscape (value of attribute)
page
line (element)
lineto (element)
linewidth (element)
linewidth (attribute)
line
llx (attribute)
annotation
weblink
lly (attribute)
annotation
weblink
moveto (element)
note (element)
open (attribute)
outline
open (value of attribute)
outline
openimagefile (element)
orientation (attribute)
page
outline (element)
page (element)
parent (attribute)
outline
path (element)
placeimage (element)
portrait (value of attribute)
page
readFromFile() (method)
rect (element)
restore (element)
rotate (element)
save (element)
scale (element)
set (element)
set_leading (element)
setfont (element)
setlinewidth (element)
setrgbcolor (element)
settemplate (element)
show (element)
showboxed (element)
showxy (element)
src (attribute)
openimagefile
subject (attribute)
document
stroke (element)
template (element)
text (attribute)
annotation
outline
title (attribute)
annotation
document
translate (element)
type (attribute)
openimagefile
url (attribute)
weblink
urx (attribute)
annotation
weblink
ury (attribute)
annotation
weblink
weblink (element)
width (attribute)
page
