Chapter 17
Creating New PDFs

cpdf -create-pdf [-create-pdf-pages <n>]
     [-create-pdf-papersize <paper size>] -o out.pdf

cpdf -typeset <text file> [-create-pdf-papersize <size>]
     [-font <font>] [-font-size <size>] -o out.pdf

cpdf -jpeg <filename> -o out.pdf]

cpdf -png <filename> -o out.pdf

17.1 A new blank PDF

We can build a new PDF file, given a number of pages and a paper size. The default is one page, A4 portrait.

cpdf -create-pdf -create-pdf-pages 20
     -create-pdf-papersize usletterportrait -o out.pdf

The standard paper sizes are listed in Section 3.1, or you may specify the width and height directly, as described in the same chapter.

17.2 Convert a text file to PDF

A basic text to PDF convertor is included in cpdf. It takes a UTF8 text file (ASCII is a subset of UTF8) and typesets it ragged-right, splitting on whitespace. Both Windows and Unix line endings are allowed.

cpdf -typeset file.txt -create-pdf-papersize a3portrait
     -font Courier -font-size 10 -o out.pdf

The standard paper sizes are listed in Section 3.1, or you may specify the width and height directly, as described in the same chapter. The standard fonts are listed in chapter 8. The default font is Times-Roman and the default size is 12.

17.3 Make a PDF from a PNG or JPEG image

Simple facilities for making PDFs from PNG and JPEG images are included in cpdf. The resulting file can be written out, or used for further operations.

For PNG files, the file must be 24bit RGB with no transparency and no interlacing.

cpdf -png image.png -o out.pdf
cpdf -png image.png AND -add-text "My Image" -o out.pdf

Almost any JPEG file may be used:

cpdf -jpeg image.jpg -o out.pdf

The output file will have one point of width or height for each pixel in the input.