Convert your spooled files into PDF with iText.
In Part
Two of this series, I presented SCS2PDF, a utility that gives you a fast way
to easily convert spooled files into PDF documents. Now, I will show you how to
make your text spooled file look better by adding graphic images, using fonts
other than standard Courier, and putting in a background color. Furthermore, you
will be able to protect the PDF document with encryption: You can specify the
"user" password required to open the document and the "owner" password that
allows other operations, like printing, copying, and changing the document.
The iText Library
Before presenting this
utility, I'd like to introduce iText, an open-source, 100% Pure Java class
library for creating and manipulating PDF documents. The first version of iText,
called rugPDF, which made only very simple PDFs, was originally published by
Bruno Lowagie in 1999 with the purpose of encouraging people to widely use it
for any purpose, including commercial/closed source/propriety software. The
latest release, V1.2, is very stable and delivers a rich set of features, and
it's constantly updated by Bruno Lowagie, Paulo Soares, and some co-workers.
iText requires JDK 1.2 and is completely free--no purchase price and no license
fee, provided that you agree with either the MPL or the LGPL license.
At
present, as far as know, there is only one free open-source implementation based
on iText that runs on iSeries; it was developed by Manolis Mariakakis a couple
of years ago. Because open-source products often face similar challenges, in
this article, you'll see again the iText API in action with my version of
SCS2ITEXT, a spooled files converter.
Getting Started
First, you will need to download the iText .jar file
from the iText Web site, where you
can find documentation, a comprehensive tutorial, and hundreds of examples. The
current iText release is V1.2, and my utility is expected to run at this level.
Move the itext-1.2.jar into your iSeries directory pdf that you created from my
previous article. Now, download the
code that accompanies this article; copy the SCS2ITEXT.class into the pdf
directory; copy all the CLP, CMD, and RPG programs into a source file; and
compile as usual.
To get the spooled file data, this utility employs the
same technique used with SCS2PDF: The CPYSPOOL records and the PF are accessed
sequentially using the record-level access classes included in the
jt400native.jar. Make sure that this .jar file is located in your iSeries
directory in /QIBM/ProdData/OS400/jt400/lib. You can optionally download the
latest version of this .jar file (4.6) directly from the IBM
site.
Note: In order to achieve better performance,
the PF/CPYSPOOL has been defined internally in the Java class. If you want to
experiment, take a look at the code for the external format; you can enable this
feature and see that performance is slower.
Finally, remember to
optimize the SCS2ITEXT class to run using OS/400 native processor instructions
by submitting this command:
CRTJVAPGM CLSF('/pdf/SCS2ITEXT.class') OPTIMIZE(40)
Try It
Now, you're ready to run SCS2ITEXT. The default
parameters produce a PDF document similar to the document generated by the RPG
version. The page options parameters are unchanged, while the new parameters
LOGO, LOGONAME, and LOGOSCALE allow you to position and size a company logo on
each page. The parameter PASSWORD allows you to encrypt the document and protect
it from being opened. For BASEFONT, you can leave the default Courier or use any
other .ttf font (which must be placed in an iSeries directory defined in the
classpath, like pdf). Fonts other than standard ones are usually copyrighted,
so make sure you are using them legally. The last parameter, JDEBUG, displays
the Java console and can help you in resolving any errors.
This is an example of the command that produces the sample PDF document
enclosed (output produced by DSPPTF with a graphic and a custom font):
SCS2ITEXT FILE(QSYSPRT) LOGO(*TOP) LOGONAME('/pdf/MCtips.gif') LOGOSCALE(75) BASEFONT('Lucida Console')
What's Next?
SCS2PDF and SCS2ITEXT allow you to convert SCS
spooled files into PDF. In the next TechTip, I will present a utility you can
use to convert AFP spooled files. Don't miss
it! Giuseppe Costagliola is a programmer in Turin,
Italy. You can reach him at
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
.
|