The PostScript::TextBlock Module
The TextBlock module is an object that may be used to construct a block of text in PostScript. It is meant to be a simple abstract interface for generating PostScript code from Perl scripts or CGI scripts such as the example in the previous section. For now, let’s look at some simple examples of using the TextBlock module:
use PostScript::TextBlock; my $tb = new PostScript::TextBlock; $tb->addText( text => "Hullabalo in Hoosick Falls.\n", font => 'CenturySchL-Ital', size => 24, leading => 26 ); $tb->addText( text => "by Charba Gaspee.\n", font => 'URWGothicL-Demi', size => 12, leading => 14 ); print 'There are '.$tb->numElements.' elements in this object.'; open OUT, '>psoutput.ps' or die "Couldn't open psoutput.ps: $!"; my ($code, $remainder) = $tb->Write(572, 752, 20, 772); print OUT $code;
As you can see, the TextBlock module allows the web programmer to create printable documents without any knowledge of PostScript. The PostScript code generated by this script looks like this:
0 setgray 0 setgray 20 746 moveto /CenturySchL-Ital findfont 24 scalefont setfont (Hullabalo in Hoosick Falls.) show 0 setgray 20 732 moveto /URWGothicL-Demi findfont 12 scalefont setfont (by Charba Gaspee.) show
The TextBlock.pm and Metrics.pm modules should be installed in the appropriate directory for your distribution of Perl. If you have downloaded the source from CPAN (which may actually be a newer version than that described here), the Makefile provided should install ...