Skip to content

Reference: XML tags

kelvin0 edited this page Apr 9, 2012 · 9 revisions

Special variables : #PAGE# and #TOTALPAGES#

These variable can be inserted freely in the XML document to specifiy the current page number and the totalnumber of pages (respectively).

Coordinates and units

The coordinate system has (0,0) as the top left of each page. The units used to specify coordinates and size correspond to 72 points/inch. For example a 8.5" x 11" page is 8.572 = 612 and 1172 = 792 (612x792).

All Tags

All tags described here support the attributes 'id' and 'class'

<rlxml>

This tag must be the root of the XML document.

Attributes: pagesize="page_width:page_height", orientation="portrait" (or "landscape")

<rlframe>

Frames are a concept used in Reportlab. They are containers in which other elements can reside. Elements within a frame cannot have posx and posy attributes, they are positionned in a 'flow' within the frame.

Attributes: posx, posy, height, width

<rlbox>

Draws a box.

Attributes: posx, posy, height, width, background-color, border, color, snapto

<rlline>

Draws a line.

Attributes: posx, posy, endx, endy, border, color

<rlellipse>

Draws an ellipse (or circle).

Attributes: posx, posy, rx, ry, border, color

<rltransform>

Allows to transform the canvas through translations, rotations and scaling. All elements within the tranform tags will be tranformed accordingly. Transforms can be nested, to compose more complex transformations as needed.

Attributes: transform = "rotate:degrees" or ... = "translate:tx:ty" or ... = "scale:multx:multy"

<head>

Has no effect on the visual appearance of generated PDF. Simply a way to partition the XML content. It is recommened the 'style(s)' tags be declared within the 'header'.

Attributes: None

<body>

Has no effect on the visual appearance of generated PDF. Simply a way to partition the XML content.

Attributes: None

<pagebreak>

This tag is ESSENTIAL in telling PyXML2PDF where each page ends. Otherwise, the generated PDF will be a blank page. It should be placed at the end of each page that needs to be part of the PDF.

Attributes: None

<styles>

This tag should be used in 'header'. It is simply a way to contain 'style' tags.

Attributes: None

<style>

This tag allows to create a named style. Each style can have specific attributes (font, color, height ...) which can be applied to a specific tag to modify it's appearance. If an attribute is also specified within a tag, it overrides the same attribute for the style used for that tag.

Attributes: name

Example:

<style name="normal">
    font-size:10;
    top-padding:0.5;
    left-padding:0.5;
    height:11;
</style>

<p>

This tags allow to create a textfield (paragraph). The text will be truncated by default if it is larger than the width. However, the 'wrap' attribute can be used to wrap the text within the width specified. All newline (\n) characters within this tag's text will be render as so in PDF document .

Attributes: background-color, font-weight, font-style, leading, color,wrap, text-align, posx, posy, height, width, snapto

<img>

This tag allows inserting images within the PDF document.

Attributes: border, border-color, posx, posy, height, src, width, snapto