Advanced contents

Using PCL commands

Using PCL commands it is possible to control the layout and font use in a document in more detail. PCL stands for Printer Control Language and is one of the standards used to control printouts to laser printers.

All PCL commands start with the ESC character (0x1B) followed by one of the commands below. The character “#” below should be replaced by a numeric value.

%A : leave hpgl mode (see “%B”)
%B : enter hpgl mode, making form2pdf ignore everything up to the “leave” command
E : reset
(s#B: primary stroke weight, 0=normal, >2 gives bold
(s#H: primary pitch, chars/inch
(s#P: 0 gives fixed spaced font Courier, and 1 gives proportional Helvetica
(s#S: primary style upright, 0=normal, 1=italics/oblique
(s#T: primary typeface, 3 gives Courier, 4, 4148 and 16602 gives Helvetica, 5 and 4101 gives Times-Roman, and anything else gives the current default font
(s#V: primary font size, also changes the linespacing
&a#L: left margin (characters, hard coded as fontsize * 2 / 3)
&d@ : underline off (ignored)
&f#S: cursor pos, 0=push, 1=pop, ignoring all movement when level>0
&l#A: paper size, 1=executive, 2=letter, 3=legal, 26=A4
&l#D: line spacing in lines/inch
&l#E: margin top, in lines
&l#F: lines per page
&l#H: paper tray (ignored)
&l#L: skip perforation (ignored)
&l#O: page orientation, 0=portrait, 1=landscape
&k#S: font size, 0=10, 1=12, 2=16 (default 12)
&l#Z: margin top, in 1/720 inch
*c : graphics commands, ignored
*v : print patterns, ignored
*p#X: move horizontal, absolute or relative, in 1/300 inch
*p#Y: move vertical, absolute or relative, in 1/300 inch

Hypertext links / XML tags

It is possible to use HTML-style tags in order to define hypertext links within a document and to generate a document outline. This requires the use of the parameter “–xml”. Example:

form2pdf –xml testwithlinks.txt output.pdf

where “testwithlinks.txt” could look something like this:

Some text
To visit our website <a href=”http://www.example.com”>click here</a>.

Links can be surrounded by a border (frame) controlled by the parameters “–linkframe” and “–linkwidth”. The linkframe parameter takes an argument specifying the style of the frame: s=solid, d=dashed, b=beveled, i=inset, u=underline. The default value is “s” for “solid”.

Using the tags h1, h2, h3, h4 it is possible to add sections to the document outline (bookmarks).

Unicode and input maps

The input data is by default considered to be in ISO-8859-1 (Latin-1). There are several options to override this.

Use –ucs2 or –ucs2be if the input file is in UCS2, big endian.

Use –ucs2le for UCS2, little endian. The UCS2 escape codes U+FFFE to force little endian and U+FEFF to for big endian, is respected. The endianness is reset at the beginning of each file.

Use –utf8 for UTF-8.

For even more flexible input handling, use –inputmap mapfile. The mapfile should reside in the directory given by –mapdir, by default /etc/form2pdf/maps.

In the “mapfile”, each line should have two fields, separated by a tab. In the first column comes the character to map from as a hex value, for example ‘=A3’. In the second column comes the unicode character to map to, in standard unicode notation. In ISO-8859-2, the character A3 maps to ‘U+0141’.

Provided in the distribution are maps for ISO-8859-1 to ISO-8859-15, and Microsoft Windows Codepage 1252.

How to print barcodes

The currently supported encodings are “code 39” and “code 128”.

  • Find a truetype font for the barcode (there are several free and commercial available), and make sure it can be found by form2pdf by copying them to the directory given by the –fontdir parameter.
  • Surrond the barcode value with the two tags “font” and “barcode”, selecting the font name and encoding.

Example:

<font name=”MW6Code128M”>
<barcode encoding=”code128″>Code 128</barcode></font>

<font name=”IDAutomationHC39M”>
<barcode encoding=”code39″>12345ABCDE/</barcode></font>

Run form2pdf with the –xml flag to enable the XML parsing.