The PostScript::Document Module

The PostScript::Document module comes with the PostScript package. It creates an abstract interface for creating generic multiple-page textual documents. You can think of a Document object as a big text block with additional attributes and methods that allow it to span multiple pages. You can also include page numbers, as well as textual headers and footers that appear on each page of the document.

You can use the Document object in a manner similar to the TextBlock object. First, instantiate a new Document using the new( ) method and a number of optional parameters defining the attributes of the page; add text elements to the document with the addText( ) method; create the PostScript as a string of code with the Write( ) method; then write the code to a file, pipe it to a process, or append it to other code. Example 11-4 is a sample script that reads a text file and appends a title, header, and footer to it.

Example 11-4. Using the Document object
#!/usr/bin/perl -w use strict; use PostScript::Document; my $doc = new PostScript::Document; $doc->addText( text => "Hullabalo in Hoosick Falls.\n", font => 'CenturySchL-Ital', size => 24, leading => 100 ); $doc->addText( text => "by Charba Gaspee.\n", font => 'URWGothicL-Demi', size => 18, leading => 36 ); $doc->addHeader(text => "Hullabaloo in Hoosick Falls", font => 'URWGothicL-Demi', size => 9, leading => 11 ); $doc->addFooter(text => "Page ##Page", font => 'URWGothicL-Demi', size => 9, leading => 11 ); ...

Get Perl Graphics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.