Creating a PDF

Configuring Form2PDF

The form2pdf binary takes numerous arguments which can be specified on the command-line or in the configuration file, /etc/form2pdf/form2pdf.cfg.

In order to display the available command-line parameters run “form2pdf –help”. All command line options have the same name in the configuration file, but in uppercase and without the dashes (e.g. SMTPHOST instead of –smtphost).

Converting a text file

In its simplest form we only need to supply the name of an input text file and the output PDF file to convert from text to PDF. Several input files can be specified, each file will begin on a new page. Example:

form2pdf first.txt first.pdf

Controlling page layout

Page dimensions are set using the “–pagewidth” and “–pageheight” parameters. The default values are 595 and 842 pixels respectively. This corresponds to an A4 page at 72 dpi. For US Letter 612 (width) and 792 (height) would be used.

Margins are set using “–marginleft” and “–margintop”, linespacing and lines per page using “–linespacing” and “–linesperpage”. Example:

form2pdf –pagewidth 612 –pageheight 792 letter.txt letter.pdf

Landscape documents

Default values in PDF for page height and page width are for A4 portrait. However, by simply switching the width and height it is possible to create a landscape document instead.

form2pdf –pageheight 595 –pagewidth 842 data.txt myfile.pdf

Adding a background image

A background image (or template) can be added to each page using the parameter “–bgimage”. The background image must be in PNG, JPEG or GIF format.

In order for Form2PDF to perform well the images should not be unnecessarily large and the pixel depth should be kept as low as possible.

The image will be scaled to the page size regardless of the actual image size. It is therefore important that the image has the same proportions as the page, otherwise it will be distorted. The default page size is 842 x 595 pixels (A4, 72 dpi). Example:

form2pdf –bgimage bg.png test.txt test.pdf

Changing the font and font size

The default font used is Courier which is a font with fixed spacing. The font used can be changed to any of the fonts which are built-in and always available in PDF readers.

It is also possible to change the size (default: 9pt) of the font by using parameter “–fontsize”. Example:

form2pdf –fontsize 12 –fontname Times-Roman test.txt test.pdf

Standard fonts:

  • Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique
  • Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
  • Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
  • Symbol, ZapfDingbats

Using external TrueType fonts

To use an external TrueType font, follow these steps:

  • Copy the font file to /etc/form2pdf/fonts, or use –fontdir dirname to load the file from another directory. If you want to use fonts from several directories, make a new directory and make symbolic links to the them. Form2PDF will follow these links, and find the entire set of fonts.
  • Run “form2pdf –showfonts”, to show the available fonts.
  • Add “–fontname FontName” to the command line, where FontName is taken from the field after the slash in the font list.

Adding to an existing PDF

Convert first page:

form2pdf first.txt first.pdf

Convert the rest of the pages adding them after the first page:

form2pdf first.pdf contents.txt output.pdf

Controlling PDF document information

It is possible to change PDF document information using the parameters below.

  • –pdftitle
  • –pdfsubject
  • –pdfauthor
  • –pdfkeywords
  • –pdfproducer
  • –pdfdescription
  • –pdfcreator
  • –pdflang

Example:form2pdf –pdftitle “Invoice 12340” –pdfsubject “This is an invoice” –pdfauthor “Bill, Sample Company Inc” –pdfkeywords “Invoice, Bill” –pdfproducer “ERP App 3.0” invoice.txt invoice.pdf