Previous: Printing in PostScript, Up: Producing printed output



8.6 Printing to PDF files

Subclasses of the printpage and printrow classes are also provided for providing output in Adobe Portable Document Format (PDF). These classes are declared in the print_pdf.h header file.

Some specific issues must be considered when creating PDF files. Firstly, although the classes support output to an arbitrary stream, some care must be taken. This is because PDF files contain tables which cross-reference different parts of the file; and these tables therefore contain byte offsets into the file. If you use the PDF printing classes to write to a text-mode file on some system, such as Microsoft Windows, which convert single line feeds to carriage-return and line-feed pairs, then this byte count will be incorrect. The safe way round this is to always open PDF output streams in binary mode.

The second specific issue which arises when creating a PDF file is that of fonts. In order to position text correctly on the page, the class library needs to know the metrics of every character in each font used. As a result, it is only possible to use the standard 14 PDF fonts when printing from the Ringing Class Library. These standard fonts are:

The printpage_pdf class is derived from printpage. The only new functions defined in this class are its two constructors:

— Constructor: printpage_pdf::printpage_pdf (ostream& o, const dimension& width, const dimension& height, bool l=false);

This constructor creates an object for writing a PDF file to the output stream o. The page width and height are set to width and height respectively. If the Boolean parameter l is set, the page will be printed in landscape format.

— Constructor: printpage_pdf::printpage_pdf (ostream& o, bool l=false);

This constructor works as the previous one, but the page size is set to A4.

The subclass of printrow for printing to a PDF file is called printrow_pdf; but as an object of this class will always be created through the parent printpage object, the programmer should never need to deal with the printrow_pdf class.