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

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 TimesRoman and the default size is 12.

Python Interface

 
# CHAPTER 17. Creating New PDFs 
 
def blankDocument(w, h, pages): 
    """ Create a blank document 
    with pages of the given width (in points), height (in points), and number 
    of pages.""" 
 
def blankDocumentPaper(papersize, pages): 
    """Create a blank document with pages of the given paper size, and number 
    of pages. """ 
 
def textToPDF(w, h, font, fontsize, filename): 
    """textToPDF(w, h, font, fontsize, filename) typesets a UTF8 text file 
    ragged right on a page of size w * h in points in the given font and font 
    size.""" 
 
def textToPDFPaper(papersize, font, fontsize, filename): 
    """textToPDF(papersize font, fontsize, filename) typesets a UTF8 text file 
    ragged right on a page of the given size in the given font and font 
    size."""