In Part One of this series, I presented a simple utility to convert your spooled files into PDF. Maybe you used a text editor to open a PDF document created with the utility and you saw that the iSeries spool was written to PDF in clear text, line by line. However, PDF includes the ability to reduce the file size by using a filter to compress all data streams. This operation can occur on the streams before they are put into the PDF document and then be applied from Acrobat Reader while processing the stream for the input PDF.
The PDF Filters
When you generate a new PDF file, you can compress text streams using a method that PDF supports as a standard filter. For each stream that has been compressed, the generated PDF object includes the /Filter key followed by the compression method used: For text data, we can use Lempel-Ziv-Walsh (LZW) and Flate filters.
LZWEncode and LZWDecode are filters for encoding and decoding data according to the LZW compression scheme (United States patent number 4558302, owned by the Unisys Corporation), and you must get a regular license to develop software using LZW.
FlateEncode and FlateDecode Filters, however, are based on the public domain zlib/deflate compression method (also called zip, the same algorithm used in popular PC applications like PKZIP or WinZip). But in order to create a compressed stream, you do not need to create a zipped file: You just use the compress algorithm from zlib as written by Jean-loup Gailly. You can either download the entire zlib source code from the zlib home page or just use the code that accompanies this article because, as I just said, you don't use the entire zlib library.
Upgrade the SCS2PDF Utility with Flate CompressionBefore you try this version of the utility, you have to perform some preliminary steps to compile the new SCS2PDFR program.
In your iSeries, first create a source file called QSCS2PDF. Then, with iSeries Navigator, create a folder called pdf and some subdirectories, as in Figure 1.
Figure 1: Create the required subdirectories. (Click images to enlarge.)
Now, you can download the utility and move the RPGLE and REXX sources into the QSCS2PDF and all the .c and .h sources into the respective IFS subdirectories you created. The sources of other modules (CMD and CLLE) are unchanged from Part One of this series.
You can create the new SCS2PDFR program that includes the C compress modules from zlib by running the MAKE REXX procedure (you can use PDM option 16). After this, you are ready to run the SCS2PDF command and see how the final PDF file can be reduced in size with the Flate compression utility.
In the next TechTip in this series, I will present a different and more sophisticated implementation of this utility. That one interfaces with the powerful Java iText APIs that allow you to create PDF documents from spooled files with custom fonts, company logo, encryption, and more. Stay tuned!