ubxml2pdf – Using xml to make a pdf form
ubxml2pdf uses an xml structure to produce forms. From simple to complex, ubxml2pdf can make your form.
The basic principle is to create a background form and then add lines to it. When the current page is full a new page with the background form is started.
Hello World!
Every language has a simple “Hello World!” program.
Here is the simple ubxml2pdf program.
<?xml version="1.0"?> <document> <form> <head> <box llx="0" lly="0" urx="8.5" ury="11.5" /> </head> <body><line><text>Hello World!</text></line></body> <foot /> </form> </document>
This shows the basic components of a document.
You can test this by editing a file to contain the above text and then using curl to send it to our pdf server:
cat test.xml | curl -s --form USER=rjm@hypedc:L1e9V7y2 --form PROCESS=ubxml2pdf --form FILENAME=@- http://uniquote.zenucom.com/cgi-bin/service
Some explanation:
<?xml version=”1.0″?>
standard xml processing command
<document> The root document. IT has options that apply to the whole document, but can be called by itself.
<form> A ubxml2pdf form consists of multiple forms, each with it’s own characteristics. Forms always start on a new page. eg You could have a form that is an invoice followed by a standard form that is terms and conditions of sale.
<head>, <body>, <foot>. Like an html table, a form is divided into a heading, body, section, and footer. Unlike an html table they are specified in the order you expect to see them.
Elements in the <head> section are put on every page. The background form if you like.
<body> has a restricted set of elements that are the lines on the form.
<tail> is cleanup at the end of the form such as a total.
<head> and <foot> sections are composed of boxes that are positioned absolutely on the page. The last box of the <head> section is the <box> used for the <body>.
Within a <box> you can have <bar> to put vertical bars in a box.
You can also have <line>, <imagetab>, <newpage>, <rule>, <barcode> (explained later).
The <box> element that defines the <body> can also have a special <heading> element. More on that later.
The simplest element is a <line> that has <text> and <image>.
Background and foreground colours and shades
Before we build a form, just a note on using gray scale (shades) and colours. These can be either background or foreground.
Colours and shades are specified as attributes of many elements: form, head, body, tail, box, line, text.
Gray scale is specified as a factor of black to white. 0 = black. 1 = white. A decimal (eg 0.5) represents the amount of white.
Colours work the same, except you specify the amount of red, green, and blue. Again as a decimal. Specifying some of each colour will give more complex colours. Much the same as you would with html (0..255 instead of 0..1).
Either shade or a factor of read, green, and blue can be given. But not both.
e.g.
<box background-shade="0.5" red="0.5" blue="0.5"> <line><text>Hello World!</text></line> </box>
This produces magento text on a gray background.
It is important to recognise at this point that these characteristics are inherited from one level to the next.
eg
<box background-shade="0.5" red="0.5" blue="0.5"> <line><text>Hello </text><text red="1" green="1">World!</text></line> </box>
Building your form
The first thing to do is build the background for your form.
This consists of lots of boxes absolutely position on the page.
A box has a position, background, borders, and then contains lines.