TechTip: Spooled Files and PDF, Part Four PDF Print E-mail
Tips & Techniques - Document Management
Written by Giuseppe Costagliola   
Thursday, 07 April 2005 18:00

Convert AFP spooled files to PDF.

by Giuseppe Costagliola

 

SCS2PDF and SCS2ITEXT, presented in previous tips, are two simple utilities that allow you to convert SCS spooled files into PDF. Many readers are now eager to know how to convert AFP spooled files as well.  

 

But before going any further, I again suggest trying IBM Infoprint Server, which allows you to  transform any iSeries output format--such as SCS, AFP, IPDS, and OfficeVision/400--into PDF. This product creates text-based, space-saving, non-image ASCII PDF files, which preserves document fidelity and provides the ability to navigate through the document and distribute information via email, Web, or local printing. Furthermore, the Infoprint Server has been designed for high volumes and reliable delivery, and the latest version, V5.3, provides new capabilities like enhanced control over PDF file names and IFS locations, easy deployment and improved usability, encryption of document (along with password protection), full-color documents, control over the orientation of a document or report in the viewer, and miscellaneous enhancements that significantly reduce average PDF file size; some of these functions are also available in V5R2 as a PTF update. The product (5722-IP1) is pre-loaded on the OS/400 release CD set and can be installed for a 70-day free evaluation. To learn more about it, take a look at the IBM Redpapers "Printing VI" (SG24-6250) and "Printing VII" (REDP-3752-00). You will find sample programs, tips, application techniques, and performance considerations.

 

However, if you don't want to spend any money or you just want to try an open-source solution, keep on reading this tip. At the end, you will be able to create your PDF documents from any SCS or AFP report for free.

 

But first, let me tell you something about Tiff, libtiff, and Host Print Transform.

Tiff and libtiff

TIFF (Tag Image File Format) is an extremely common raster image format that was originally produced by Adobe, and libtiff is a set of C functions (a library) that support the manipulation of TIFF image files. The libtiff package, which can be downloaded from the Web, contains the tiff libraries and associated utilities. Among these utilities, you can find tiff2pdf, a C program that converts one TIFF file to one PDF file, including multiple page TIFF files, tiled TIFF files, as well as black and white and color TIFF files.

Host Print Transform

The Host Print Transform (HPT) API QWPZHPTR allows you to convert an AFPDS data stream to a TIFF file. (For more information, see the API Reference.) To generate a TIFF file, this API requires the IBM-supplied QWPTIFFG4 WSCST object, which can be found in QSYS. However, you can create your own Work Station Customization Object (WSCST) by running the CRTWSCST command against these instructions:

 

:WSCST DEVCLASS=TRANSFORM.
:TRNSFRMTBL.
:PRTDTASTRM DATASTREAM=TIFF_G4.
:INITPRT DATA ='4D4D002A'X.
:RESETPRT DATA ='00000000'X.
.EWSCST.

The AFP2PDF Utility

Let's put things together so you can build your utility that first converts spooled files into TIFF and then TIFF into PDF.

 

The HPT API creates a TIFF file that contains single-strip CCIT G4 compressed information (it's like a black and white scan) that is written directly to PDF from the tiff2pdf program without transcoding, thus making this final step very fast. The HPT API in this utility has been designed to convert spooled files one at a time; however, if you require heavier usage, you will dramatically reduce the CPU usage (and the conversion time) by initializing the HPT engine at the beginning of the job and terminating when all processing is complete. You can find detailed information in the QWPZHPTR API reference. The intermediate TIFF can also be re-sampled in order to achieve the best quality at the lowest PDF size, but this will be discussed in a future issue.

 

To see this utility in action, first create in your iSeries a subdirectory called libtiff-3.7.2 under the \pdf directory you created in Part Two of this series and a source file called QAFP2PDF. Download the content of the libtiff-3.7.2, and move the source files into your iSeries subdirectory. Then download the other source files into the QAFP2PDF. Because you won't use the entire libtiff source library, you will find only the modules needed by this implementation and an iSeries version of the unix.c and tiff2pdf.c modules, but you can download the entire library here. Finally, run all five MAKE REXX files in the correct sequence in order to create the CLE program TIFF2PDF, and compile all the RPG, CMD, and CLLE as usual.

Try It

If you already produce AFP reports, just run the AFP2PDF command to put the PDF in the specified IFS directory. But if you never created an AFP report, follow these steps to test the utility:

  1. Create a printer driver on a PC that has Client Access Express: Control Panel>Add Printer>Local Printer>Print to File>IBM AFP240.
  2. Design the overlay using a PC application like Microsoft Word. 
  3. Print it to the AFP printer that you just created; make sure the Output Type is Overlay. You will be prompted for the directory and name where the overlay should be put.
  4. Open iSeries Navigator, and in the left panel, expand AFPmanager and Resources. Right-click Overlay and Import your overlay.
  5. Override your print file with DEVTYPE(*AFPDS) and FRONTOVL(library/overlay).
  6. Create your AFP report.  

 

Enjoy creating your PDF directly from this spooled file!

 

Download all files by clicking here.

 

 


Giuseppe Costagliola
About the Author:

Last Updated on Monday, 26 July 2010 13:01
 
MC Press Web Site Staff
** This thread discusses the Content article: TechTip: Spooled Files and PDF, Part Four0
ggirouard@baltex.com
Thanks for all these tips on PDF, it\'s really fine. For the part four I have a little problem. The creation of the PDF is working fine, but the overlay on the PDF is starting 1 inch lower than before, so my text is no more align with the overlay. If you have any idea I will appreciate. Thanks, Guy.
gcostagliola@tin.it
Guy, you can try playing with parameter PAGESIZE but consider that we do not have any control on the HPT api. When you create a pdf, don\'t delete the intermediate tiff file and examine it with a viewer (like MSOffice Document Imaging or Imaging for Windows). This is what goes into Pdf. If you find there any unalignment I\'m sorry but there is nothing that we can do, apart from installing the latest PTF or asking IBM because the tiff generation relies on a system Api. However if the tiff image is perfect and gets spoiled after pdf conversion, tet us know.
Guest.Visitor
Thanks for great article. Do you know if the API converts a color data into proper colors in TIFF and subsequently in PDF? Thanks, Dmitriy Kuznetsov
ggirouard@baltex.com
Hi Costagliola, I looked at the tiff file and the tiff is identical to the PDF and the unalignment is present there too. So, I assume that I missed some PTF on my AS400. Thanks, Guy
gcostagliola@tin.it
In any case try to put different values into QWPPS1 and QWPPS2 Api parameters. In some cases *MFRTYPMDL is the best choice, but sometimes you get a better overlaying wit *A4 or *LETTER.
gcostagliola@tin.it
HPT with QWPTIFFG4 WSCST creates a Tiff compressed G4 and does not recognizes the dds keywords AFPRSC that allows to include a color image.
gcostagliola@tin.it
If you want to store a PDF into a QDLS subfolder change stmt 138 in AFP2PDFC as follows: CHGVAR &TIFF (&PDFPATH *TCAT &PDFNAME *TCAT \'.tif\')
CHRISTOPHER HAMMAC
My spool file is 110 characters. It appears that the text is wrapping to the next line. How do I get the pdf to keep the text on one line
gcostagliola@tin.it
AFP2PDF in intended to create a PDF for a A4 or Letter spool with graphics (invoices, account statements, etc). Other text spool can be converted to pdf with SCS2xxx. In any case we rely on HPT IBM Api. To further investigate, don\'t delete the intermediate TIFF and examine it with a windows tiff viewer. If it is bad there there is nothing that we can do. TIFF2PDF allows custom pagesizes but if converts the tiff as is.
Guest.Visitor
Let me begin by saying that this set of programs has been a joy in our shop since I installed it. In our process we generate the spool file and then produce the PDF which is sent via e-mail to our customers. The problem that I am experiencing is that occasionally without any pattern that I can identify we get e-mail documents that show the raw output instead of the neatly packaged PDF file. Is there something that I should be looking at?
gcostagliola@tin.it
what e-mail program do you use ? QtmmSendMail api has been said to have this problem with attachments but I\'ve never used it.
Guest.Visitor
We are using SNDDST.
gcostagliola@tin.it
If the PDF opens fine before being e-mailed I\'m quite sure that it is corrupted by SNDDST but I never used that command. You can search internet for a free mail program to use instead of SNDDST
Guest.Visitor
I copied a database to IFS using cpytoimpf command and it was perfect. CPYTOIMPF FROMFILE(MYLIB/KMRLBL) TOSTMF(\'QDLS/MYIFS/KMRITM.CSV\') MBROPT( [*>REPLACE) STMFCODPAG(*PCASCII) RCDDLM(*CRLF). But when I send it to my email, the leading zeros has been truncated for a character field. How to fixed this problem. When I looked at the record in IFS the leading zeros are there but when I open the attachment in excel the leading zeros are truncated although its character field. TIA Tiki
David Abramowitz
The problem is not with anything that you are doing on the AS400, but rather with excel. Format the column as custom and specify 0000000 for the mask. Dave
jfrankman
We are having problems with the fonts from an AFP report being converted correctly. To illustrate the point we wrote an AFP report prints out all the different fonts on our iSeries. I have added three Attachements: 1. The first attachment is what the report looks like when we release the spool file directly to the printer. (I printed the page out and then scanned it into a JPG file.) 2. The second attachment is the spool file converted to tiff by the programs presented in your fourth article on PDF conversion. 3. The third attachment is the pdf that gets converted from the tiff. You will notice that the fonts in the printed spool file do not match those fonts in the tiff and pdf. Do you have any ideas as to why this is happening?[file name=6b272220_Spool2PDF.zip size=24>http://www.mcpressonline.com/images/fbfiles/files/6b272220_Spool2PDF.zip[/file>
gcostagliola@tin.it
When you print your spool, the printer uses resident fonts or mapped according to the printer specific wscst. When you convert to tiff there are no resident fonts. In practice a dds that contains: A TEXT 30 FONT(4407 (*POINTSIZE 12)) probably will print fine on a afp printer but won\'t properly convert to tiff. while A TEXT 80 FNTCHRSET(C0H200B0 T1001144) should convert to tiff.
jfrankman
We have two forms, one created by Microsoft Word and the other by Microsoft Publisher. When we send the forms through the AFP2PDF routine, both the Microsoft version and the Publisher version comes out fine if the user profile has security officer level clearance. If the user profile is less then a security officer level, however, only the PDF derived from Miscrosoft Word version works. The PDF derived from the Publisher version turns out junk that is not recognized as a tiff by the tiff2pdf program. Any ideas as to why this is happening? P.S. I have included the two forms(overlays) in the attached save files if you need to take a look.[file name=6b274b98_AFPOverLays.zip size=24>http://www.mcpressonline.com/images/fbfiles/files/6b274b98_AFPOverLays.zip[/file>
Mike_59
When I try to compile at V5R1 I get the following errors: InfBuffer += QSPLBI; // Length Buffer Info QWPNBRCP -= 1; // Number Complete Pages QWPNBRCP += 1; // Number Complete Pages (Expecting an assignment operator) Which I changed to: InfBuffer = InfBuffer + QSPLBI; // Length Buffer Info QWPNBRCP = QWPNBRCP - 1; // Number Complete Pages QWPNBRCP = QWPNBRCP + 1; // Number Complete Pages Also, the following fields are undefined: QWPJSN, QWPSCD, and QWPSCT Can you guide me as to what I can do to correct the undefined issues? Thanks, Mike
Mike_59
All of my problems were related to compiling at V5R1. The corrections mentioned above to the "+=" operations were the correct ones. The fields that were not defined were added in the V5R2 version of the QWPZHPTR (QwpzHostPrintTransform) API. I had to: 1) Remove (comment out) them from the end of the associated prototype definition (QSPOPNSP) 2) Change the call to QSPOPNSP to have only 8 parameters (drop the last three). 3) Remove (comment out) the use of the fields when ProcessOption = 20 After the above changes, the program worked fine. Thanks, this will fill our needs.
Colin Grierson
I am trying to transform AFP files now and have a very similar alignment problem. I have tried using *A4 and *Letter, they change my results but don\'t fix the problem. I don\'t see any relevant PTFs for the transformation API. Did you find a solution to the problem? Thanks Colin And thanks to Costagliola for a great tool - if I can get IBM\'s part working.
gcostagliola@tin.it
You can create only the pdf: move the overlay position in the dds in order to get a perfet alignment. Then you print the pdf directly. There are many ways to do it, for example: QIMGCVTI (if you have infoprint), "pdfp.exe" if you can runrmtcmd, Ghostscript if you like the Pase adventure, and more freeware tools that "listen" to a folder and print the pdf as soon as it arrive .... and forget the spooled file. My utility relies on a IBM API. If the resulting image is already misaligned, just ask IBM to fix.
Guest.Visitor
Hi, Thank you for wonderful utility. recently we started using AFP2PDF utility to convert spool files to PDF then merge them to single PDF. we send it as email. we are getting this message Intermittently. we added monitor message for it. on the next successful conversion we are getting merged PDF file with spool files that had this error. How can we stop this. How can we handle resource busy message. our OS/400 version is V5R3.I have attached joblog Please let me know if you need additional information. thanks for your advice, sayi.
[size="1">Code[/size>
Pietrob
I am trying AFP2PDF, bur it resoults with the following error can you explain me how to resolve it\' Thanks in advance Pietro Battisti -------- ID messaggio . . . . . : CPF9898 Data di invio . . . . : 19/10/06 Ora di invio . . . . . : 14:45:10 Messaggio . . . : TIFFReadDirectory: /conversioni/GOCA15P.tiff: Can not read TIFF directory count.
Please login to make comments.
User Rating: / 1
PoorBest 

   MC-STORE.COM