Portable Document Format (PDF) was designed by Adobe more than 10 years ago for exchanging documents under Windows, Mac, and UNIX platforms. Documents are independent from the software and operating system used to create the files, so a document created in any one of those platforms looks the same on any of the other platforms. Adobe published the first PDF specifications in 1993; since then, Adobe has updated the specifications and made them available for download.
Developers require no licensing to create their own software to read and create PDF documents for both private and commercial uses. Adobe desires to promote the use of the PDF not only for information interchange but also as a preferred standard for electronic archiving.
Nowadays, almost everyone has downloaded the free Acrobat Reader that allows printing and viewing PDF documents with magnification, full text search, and other facilities. The file can be viewed without the originating application, and soon users will be able to view documents exactly as they were created. In addition, the final document can be encrypted and password protected from being copied, modified, or printed.
A standard PDF document is organized into four major parts:
- The header identifies the version of the PDF specification to which the file conforms.
- The body is a collection of objects (text streams, image data, fonts, annotations, etc.) that make up the document contained in the file.
- The cross-reference table contains offsets to all the objects in the body.
- The trailer gives the location of the cross-reference table and of certain special objects within the body of the file.
All the specifications in a PDF file are arranged into lines terminated by an end-of-line(EOL) marker. PDF files with binary data, such as images or compressed text streams, may have lines of any length, while lines that are not part of stream object data are limited to no more than 255 characters.
PDF as an Archiving Format for Spooled Files
Now you know how a canonical PDF file is organized. Because Adobe encourages the use of the PDF for information interchange among diverse products and applications and gives permission to anyone to prepare files in which the content conforms to PDF, I now present SCS2PDF, a simple but complete utility entirely written in RPG that converts iSeries spooled files into a PDF document. In the second TechTip of this series, I will present an enhanced version of the same utility that encodes text using the Flate compression method and reduces the size of the PDF file. In the third TechTip, I will present another way of converting spooled files into PDF by using the iText free Java APIs; this utility allows you to add some nice features to your spool PDF, including custom fonts, logos, and file protection with encryption and password. While these three utilities can be used for converting and archiving plain-text reports (SCS spool), in the fourth TechTip, I will show you how to port the C libTIFF APIs into your iSeries to create graphical PDF documents from any AFP reports.
The rules described in PDF basics and the sample provided by Adobe in the PDF specifications are sufficient to write the following simple utility that converts your spooled files into a well-formed PDF document. Just consider that this is a simple, general-purpose utility; for a heavy-duty spool conversion, you may consider a third-party product like IBM InfoPrint Server (which I'll present in the fourth TechTip). Commercial products enforce some additional rules for organizing a PDF file to enable efficient incremental access to a document's components in a network environment. They also apply techniques to reduce both the size of the file and the amount of memory and time needed to display pages.
To try this utility, download the source code and compile as usual. Just remember to create the PF/CPYSPOOL in QGPL with MAXMBRS(*NOMAX). The SCS2PDF command will quickly generate the PDF document from your spooled file and store it in a directory in the IFS, ready for emailing or for accessing via iSeries clients or Web clients.
Giuseppe Costagliola is a programmer in Turin, Italy. You can reach him at email@example.com.