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.

C Interface

 
/* CHAPTER 17. Creating New PDFs */ 
 
/* cpdf_blankDocument(width, height, num_pages) creates a blank document with 
 * pages of the given width (in points), height (in points), and number of 
 * pages. 
 */ 
int cpdf_blankDocument(double, double, int); 
 
/* 
 * cpdf_blankDocumentPaper(papersize, num_pages) makes a blank document given 
 * a page size and number of pages. 
 */ 
int cpdf_blankDocumentPaper(enum cpdf_papersize, int); 
 
/* cpdf_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. */ 
int cpdf_textToPDF(double, double, int, double, const char[]); 
 
/* cpdf_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. */ 
int cpdf_textToPDFPaper(int, int, double, const char[]);