TechTip: Spooled Files and PDF, Part Four PDF Print E-mail
Written by Giuseppe Costagliola   
Thursday, 07 April 2005

Convert AFP spooled files to PDF.
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!

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 .


Last Updated ( Thursday, 07 April 2005 )
 
Discuss (28 posts)
lujate
Re:TechTip: Spooled Files and PDF, Part Four
Feb 15 2008 22:43:18
We have been using the AFP2PDF command for some time. It is now causes problems with the latest version of Adobe Professional. The PDF files that AFP2PDF creates are PDF Version 1.1, which I am told is extremely out of date. I considered trying to update the libtiff and zlib directories but am reluctant to tinker with anything I do not fully understand.

Any ideas?
#121740
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Mar 16 2007 21:03:00
Seems I did not have QFNTCPL on my system. I am now getting the pdf, but it seems that I am getting "bad magic number 6950" on spool files that are generated with an overlay/form using iForm. Any ideas on what my cause this?
#118389
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Mar 16 2007 19:58:00
I am also getting this error. Did you ever resolve it? If so how?
#118388
Pietrob
TechTip: Spooled Files and PDF, Part Four
Oct 19 2006 09:49:00
I am trying AFP2PDF, bur it resoults with the following error can you explain me how to resolve it' <BR>
Thanks in advance <BR>
Pietro Battisti <BR>
-------- <BR>
ID messaggio . . . . . : CPF9898 <BR>
Data di invio . . . . : 19/10/06 Ora di invio . . . . . : 14:45:10 <p>Messaggio . . . : TIFFReadDirectory: /conversioni/GOCA15P.tiff: Can not read <BR>
&nbsp;&nbsp;TIFF directory count.
#118387
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Sep 20 2006 00:06:00
Hi, <BR>
&nbsp;&nbsp;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. <p>thanks for your advice, <p>sayi. <p><!--mccodelink_begin--> <BR>
<!-- do not remove --> <BR>
<hr width=50 align=left><small><a href='http://www.mcpressonline.com/mc/showcode@@.6b240d1c/24' target='_blank'>Code</a></small> <BR>
<!--mccodelink_end-->
#118386
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
May 11 2006 03:49:00
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. <BR>
My utility relies on a IBM API. If the resulting image is already misaligned, just ask IBM to fix.
#118385
Colin Grierson
TechTip: Spooled Files and PDF, Part Four
May 11 2006 01:09:00
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? <p>Thanks <BR>
Colin <p>And thanks to Costagliola for a great tool - if I can get IBM's part working.
#118384
Mike_59
TechTip: Spooled Files and PDF, Part Four
Aug 15 2005 19:17:00
All of my problems were related to compiling at V5R1. <BR>
The corrections mentioned above to the "+=" operations were the correct ones. <BR>
The fields that were not defined were added in the V5R2 version of the QWPZHPTR (QwpzHostPrintTransform) API. I had to: <BR>
1) Remove (comment out) them from the end of the associated prototype definition (QSPOPNSP) <BR>
2) Change the call to QSPOPNSP to have only 8 parameters (drop the last three). <BR>
3) Remove (comment out) the use of the fields when ProcessOption = 20 <BR>
After the above changes, the program worked fine. <p>Thanks, this will fill our needs.
#118383
Mike_59
TechTip: Spooled Files and PDF, Part Four
Aug 12 2005 18:21:00
When I try to compile at V5R1 I get the following errors: <BR>
InfBuffer += QSPLBI; // Length Buffer Info <BR>
QWPNBRCP -= 1; // Number Complete Pages <BR>
QWPNBRCP += 1; // Number Complete Pages <BR>
(Expecting an assignment operator) <p>Which I changed to: <BR>
InfBuffer = InfBuffer + QSPLBI; // Length Buffer Info <BR>
QWPNBRCP = QWPNBRCP - 1; // Number Complete Pages <BR>
QWPNBRCP = QWPNBRCP + 1; // Number Complete Pages <p>Also, the following fields are undefined: <BR>
QWPJSN, QWPSCD, and QWPSCT <p>Can you guide me as to what I can do to correct the undefined issues? <p>Thanks, <p>Mike
#118382
jfrankman
TechTip: Spooled Files and PDF, Part Four
Aug 10 2005 15:11:00
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>P.S. I have included the two forms(overlays) in the attached save files if you need to take a look.
File Attachment:
File Name: 6b274b98_AFPOverLays.zip
File Size: 24
#118381
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Aug 03 2005 11:49:00
When you print your spool, the printer uses resident fonts or mapped according to the printer specific wscst. <p>When you convert to tiff there are no resident fonts. <p>In practice a dds that contains: <BR>
A TEXT 30 FONT(4407 (*POINTSIZE 12)) <BR>
probably will print fine on a afp printer but won't properly convert to tiff. <p>while <BR>
A TEXT 80 FNTCHRSET(C0H200B0 T1001144) <BR>
should convert to tiff.
#118380
jfrankman
TechTip: Spooled Files and PDF, Part Four
Aug 03 2005 11:04:00
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: <p>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.) <p>2. The second attachment is the spool file converted to tiff by the programs presented in your fourth article on PDF conversion. <p>3. The third attachment is the pdf that gets converted from the tiff. <p>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 Attachment:
File Name: 6b272220_Spool2PDF.zip
File Size: 24
#118379
David Abramowitz
TechTip: Spooled Files and PDF, Part Four
Jul 08 2005 16:18:00
The problem is not with anything that you are doing on the AS400, but rather with excel. <p>Format the column as <u>custom</u> and specify 0000000 for the mask. <p>Dave
#118378
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Jul 08 2005 15:25:00
I copied a database to IFS using cpytoimpf command and it was perfect. CPYTOIMPF FROMFILE(MYLIB/KMRLBL) TOSTMF('QDLS/MYIFS/KMRITM.CSV') MBROPT( <li>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
#118377
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Jul 08 2005 11:57:00
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
#118376
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Jul 08 2005 09:04:00
We are using SNDDST.
#118375
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Jul 07 2005 11:44:00
what e-mail program do you use ? <BR>
QtmmSendMail api has been said to have this problem with attachments but I've never used it.
#118374
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Jul 07 2005 11:29:00
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?
#118373
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Apr 21 2005 04:33:00
AFP2PDF in intended to create a PDF for a A4 or Letter spool with graphics (invoices, account statements, etc). <BR>
Other text spool can be converted to pdf with SCS2xxx. <BR>
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.
#118372
CHRISTOPHER HAMMAC
TechTip: Spooled Files and PDF, Part Four
Apr 20 2005 18:37:00
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
#118371
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Apr 19 2005 12:09:00
If you want to store a PDF into a QDLS subfolder change stmt 138 in AFP2PDFC as follows: <p>CHGVAR &TIFF (&PDFPATH *TCAT &PDFNAME *TCAT '.tif')
#118370
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Apr 11 2005 05:07:00
HPT with QWPTIFFG4 WSCST creates a Tiff compressed G4 and does not recognizes the dds keywords AFPRSC that allows to include a color image.
#118369
gcostagliola@tin.it
TechTip: Spooled Files and PDF, Part Four
Apr 11 2005 05:02:00
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.
#118368
ggirouard@baltex.com
TechTip: Spooled Files and PDF, Part Four
Apr 08 2005 16:27:00
Hi Costagliola, <p>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. <p>Thanks, Guy
#118367
Guest.Visitor
TechTip: Spooled Files and PDF, Part Four
Apr 08 2005 15:05:00
Thanks for great article. Do you know if the API converts a color data into proper colors in TIFF and subsequently in PDF? <p>Thanks, <BR>
Dmitriy Kuznetsov
#118366
There are too many comments to list them all here. See the forum for the full discussion.

Discuss...
User Rating: / 0
PoorBest 
Related Articles
< Prev   Next >

   MC-STORE.COM