Chapter 11. Using the PostScript Modules

In this chapter, we develop a framework for easily generating PostScript code from Perl scripts. These modules are useful for creating printable reports from various data sources, and could even be used as the backend of a Perl-based page layout application. I’ve used this framework as part of a web-based scheduling database; the click of a hyperlink produced nicely formatted PostScript calendars and press releases. These reports could be previewed on a user’s workstation using the GhostView PostScript viewer and then sent directly to the printer.

The PostScript package includes three main modules: PostScript::TextBlock, PostScript::Document, and PostScript::Elements.

This chapter starts by presenting the TextBlock module, which is a simple object for encapsulating a piece of text that can be composited into a square block on a page. The TextBlock object makes it easy to create tabular PostScript reports. The Document object builds on the TextBlock object, providing a “document” object that allows you to place text over multiple pages. A document can also have headers, footers, and page numbers. Finally, the Elements module provides methods for generating the PostScript code to draw primitive shapes such as lines, boxes, and circles. You can also place previously created EPS files with this module.

The metaphor followed by the TextBlock and Elements interfaces is similar to that of Adobe’s PageMaker layout program. Starting with a blank page, ...

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.