strpdf

strpdf creates single-page PDF files populated with one-line text strings. The page size and string placement are configured with command line options. It is a purposely simple tool.

Download

Installation instructions and other notes are included with the downloads.

Usage

Strings are placed on the page with the -text option. General configuration options must be given before the first -text option. PDF data is printed to stdout, so redirection should be used to capture the result.

Here is a simple example:

strpdf -text 'Hello, world!' center middle > helloworld.pdf

The -text option has three parameters. The first is the string to print. The second and third specify the horizontal and vertical locations of the string on the page, respectively. Valid horizontal positions are left, center, and right. Valid vertical positions are top, middle, and bottom. The left, right, top, and bottom positions must each be followed by an additional parameter which specifies the distance from the indicated edge of the page to the closest side of the string.

Multiple instances of the -text option can be used to place multiple strings on the page:

strpdf -text 'Upper right' right 0.5 top 0.5 -text 'Lower left' left 0.5 bottom 0.5 > corners.pdf

The default page size is 8.5 × 11 inches (letter). The -paper option understands a few other common paper sizes, which can be listed with strpdf paper:

strpdf -paper a4 -text 'A4 FTW' center top 1 > a4.pdf

Alternatively, arbitrary page dimensions can be specified with the -width and -height options:

strpdf -width 5 -height 5 -text 'Square' center middle > square.pdf

By default, page dimensions and string position parameters are interpreted as inches. The -units option allows these values to be given in millimeters or points. The supported -units parameters are mm, pt, and in.

The -orient option provides a landscape mode that swaps the width and height of the page. This can be done manually with the -width and -height options, but the landscape option is convenient for use with preset paper sizes:

strpdf -paper legal -orient landscape -text 'Legal fine print' center bottom 0.5 > landscape.pdf

The default font is 12-point Helvetica. The -size option sets the font size (in points) and the -font option sets the font face. If given before the first -text string, these options set the default font. Given after the parameters of a particular -text option, they modify only that string:

strpdf -font Times-Roman -size 18 -text 'One' left 1 top 1 -text 'Two' center top 1 -size 24 -font Courier -text 'Three' right 1 top 1 > fonts.pdf

Valid font faces can be listed with strpdf font. Valid fonts are not necessarily available on your computer, nor are the fonts on your computer necessarily compatible with strpdf.

There is a -compress option which will compress the PDF data if given the
parameter 1, but in most cases it yields little benefit. For small files such
as the examples on this page, compression may actually result in slightly larger files.

Applications

I use strpdf in conjunction with pdftk to “stamp” otherwise static PDF documents with bits of variable text. Because these are both free command line utilities, the process is easily automated and requires no commercial software. Here a registration string is stamped on each page of a report:

strpdf -text 'Registered to John Doe' center top 0.25 > registration.pdf
pdftk document.pdf stamp registration.pdf output registered-document.pdf

Alternatively, strpdf’s output can be piped directly to pdftk:

strpdf -text 'Registered to John Doe' center top 0.25 | pdftk document.pdf stamp - output registered-document.pdf

Posted on Monday, November 26th, 2007. Tags: , , .