Sams spongepants were thirsty body this is the title

This preview shows page 341 - 344 out of 480 pages.

"Sam\'s Spongepants were thirsty...", %body);
This is the Title of the Book, eMatter Edition Copyright © 2013 O’Reilly & Associates, Inc. All rights reserved. 326 | Chapter 11: Using the PostScript Modules 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 meth- ods 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 ); # Now read in a big text file and add it open I, "example.txt" or die "Couldn't open example.txt: $!"; undef $/; my $text = <I>; $doc->addText( text => $text,
This is the Title of the Book, eMatter Edition Copyright © 2013 O’Reilly & Associates, Inc. All rights reserved. addHeader( ) | 327 The PostScript::Document module is installed when you install the PostScript pack- age. The module implements the following five methods. new( ) $doc = PostScript::Document->new( paper => paper , width => width , height => height , rmargin => rmargin , lmargin => lmargin , tmargin => tmargin , bmargin => bmargin ); This method instantiates a new object of class PostScript::Document. There are seven attributes that may optionally be set when a new object is created: a paper attribute, which can be one of the valid paper size strings (e.g., 'Letter' , 'Legal' ); the width and height of the page (in points); and the four margins of the page (also in points). Note that if you specify the paper attribute, you do not have to include the width and height attributes, and vice versa. The default values are 'Letter' paper (612 × 792 points) and margins of .5 inches (36 points). addText( ) $doc->addText( text=> text , font=> font , size=> size , leading=> leading ) The addText() method performs just like the PostScript::TextBlock::addText() method described in the previous section. In fact, the document simply calls the addText() method of its content TextBlock. If the font , size , or leading attributes are not provided, the default attributes for the TextBlock object are used.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture