TechTip: More iSeries PDF Wizardry Print
Tips & Techniques - Document Management
Written by Giuseppe Costagliola   
Thursday, 26 January 2006 18:00


Last year, I presented a series of articles, with three utilities, that showed how to convert a spooled file into a PDF document: SCS2PDF and SCS2ITEXT are suitable for SCS spooled file conversion, while APF2PDF can be used for both SCS and AFP spooled files.

In addition, I showed in Appendix A how to encrypt and digitally sign a final PDF document and in Appendix B how to easily allow an intranet user to get a PDF directly without any preliminary writing into the IFS.

In this article, I would like to share three new utilities that add functionality to existing PDFs, no matter what tool you used to produce them:

  • PDF Stamping allows you to add watermarks, addresses, page numbering, etc. to an existing PDF.
  • PDF Extract allows you to extract pages from an existing PDF.
  • PDF Concat allows you to concatenate up to 64 PDFs into a one PDF.

Note: If you haven't read "TechTip: Spooled Files and PDF, Part Three," where I introduced the iText library, you'll need to do so because these utilities rely on this Java class library. However, because we will use some new functionality that has recently been added to this library, you have to download the latest version, called the Early Access Version. The current Early Access Version at lowagie.com is itext-1.3.6.jar. But before downloading and using this Java library, please carefully read the iText License Agreement.

When you download the itext-1.3.6.jar, put it into the same /pdf directory that you created in your iSeries for the previous utilities; this latest version can also replace the old version we used for SCS2ITEXT.

In order to significantly enhance the Java performance, I strongly suggest that you create an iSeries Java program from this Java jar file by running this command in batch:

CRTJVAPGM CLSF('/pdf/itext-1.3.6.jar’) OPTIMIZE(40) 

Now, download the code that accompanies this article. Copy the ADDWMTXT.class, CONCATPDF.class, and EXTRACTPDF.class files into the pdf directory. Copy all the CLLE, CMD, and RPG programs into a source file and compile as usual. If you need to recompile all the above classes, run the ADDWMXPDFJ, CONCATPDFJ, and SCS2ITEXTJ CL programs that are part of the download.

Finally, optimize these Java classes with the following commands:

CRTJVAPGM CLSF('/pdf/ADDWMTXT.class') OPTIMIZE(40)    
CRTJVAPGM CLSF('/pdf/CONCATPDF.class') OPTIMIZE(40) 
CRTJVAPGM CLSF('/pdf/SCS2ITEXT.class') OPTIMIZE(40) 

You are now ready to play with these new utilities.

ADDWMXPDF (Add Watermark/Page Number)

This utility can be used to stamp watermarks, such as "Confidential" on pages that include sensitive information, or "Draft" on a preliminary PDF to be distributed for review, or your company logo. In fact, you can even put one logo on the first page and a different logo on the following pages. In addition, you can add up to six lines of text to the first page. For example, you can add the recipient name and address and/or the document date. This date can be optionally editable and changed at printing time. And finally, you can put the page number.

This is an example of how you can use this command:

ADDWMXPDF 
  FROMPDF('/sales/letters/Template.pdf')   
  TOPDF('/sales/letters/PartCatalog.pdf') 
  WTMK1NAME('/sales/images/AM1bw.jpg') WTMK1SCALE(60) 
  WTMK2NAME('/sales/images/AM2bw.jpg') WTMK2SCALE(60) 
  ADDRESS(*YES) ADDRESSPOS(320 745)
  ADDRESSLN(‘Name’ ‘Street’ ‘Town’ ‘Country’) 
  DATELN('February 4, 2005') DATEPOS(320 650) DATEEDIT(*YES)
  PAGENBR(*YES) PAGENBRPOS(560 15) 

ADDRESSPOS, DATEPOS, and PAGENBRPOS metrics use the standard Adobe PDF coordinate space. The origin of this space is at the bottom left of the document. Distances are measured up and to the right in points. Points are a traditional measure for print work; there are 72 points in an inch. In the example, the first line of the address is positioned 320 points from the left of the page and 745 points up from the bottom. The PdfCoordinates.gif enclosed in the download can help you find the coordinates where the text should be placed.

EXTPDF (Extract Pages from PDF)

This utility lets you split up one or more PDF documents based on page numbers and/or page ranges. By combining page numbers and ranges, you can specify which pages should be merged together to form a new PDF, like in the following examples:

EXTPDF
FROMPDF('/sales/catalogs/computer.pdf')
TOPDF('/sales/catalogs/offers.pdf')
SELECTION('1-5 , 10-12 , 15-17')

This will extract pages 1 to 5, 10 to 12, and 15 to 17.

You can specify both page numbers and ranges like this:
SELECTION('1,3,5, 15-17')

This will extract pages 1, 3, 5, 15, 16, 17.

You can also extract pages going backward:
SELECTION('12-5')

This will create a new PDF document that contains pages 12, 11, 10 ... to 5.

CONCATPDF (Concatenate PDF)

This utility lets you merge up to 64 PDFs into one final PDF document. Pages from multiple input documents are sequentially copied (appended) into a new output document. Here's an example:

CONCATPDF
INPDF('/sales/catalog/CPU.pdf'
'/sales/catalog/HDISK.pdf'
'/sales/catalog/KBOARDS.pdf'
'/sales/catalog/MONITORS.pdf')
OUTPDF('/sales/catalog/COMPUTERS.pdf')

Remember that, should you have any trouble running these commands, the parameter JDEBUG(*YES) opens the Java console and helps you find—and possibly solve—any error.

This article completes a collection of PDF utilities that I hope you find useful. I welcome suggestions for improvements and for other utilities.

Giuseppe Costagliola is a programmer in Turin, Italy. You can reach him at beppecosta@yahoo.it.


Giuseppe Costagliola
About the Author:

Last Updated on Tuesday, 19 October 2010 10:58
 
User Rating: / 2
PoorBest 

Related Articles: