I have times when a user will request that a report be emailed to them, rather than printed and sent to them via the inter company mail. The easiest way would be to create a PDF file from the spool file and then email it to the requestor.
There are many third party tools that allow you to be able to convert a spool file to PDF, but how can I do it just using native IBM i features?
The method I am going to describe can only be used IBM i servers with either version 6.1 or 7.1 installed.
Before you can do what I will describe in this post you need to check if you have the necessary licensed program, Transform Services, installed on your IBM i. The documentation states you can use the CHKPRDOPT command to check if it is installed, but I have found it to give false positives on some IBM i servers.
I rely on viewing the list of licensed programs to see if it is there. Type: GO LICPGM and press Enter. Then take option 10 to ‘Display installed licensed programs’. The licensed program code if different depending upon which release your server is running:
- Version 7.1: 5770TS1.
- Version 6.1: 5761TS1.
Scroll through the list of programs to find the following (this is from a 7.1 server):
Licensed Installed Program Status Description 5770TS1 *COMPATIBLE IBM Transform Services for i 5770TS1 *COMPATIBLE Transforms - AFP to PDF Transform
Transform Services is a free product that comes on the following disks of the install media:
- Version 7.1: B_GROUPx_04 disk.
- Version 6.1: B29xx_02 disk.
If it is not installed on your server ask your IBM i administrator to install:
- Version 7.1: 5770TS1 and 5770TS1 option 1.
- Version 6.1: 5761TS1 and 5761TS1 option 1.
And now to the programming… In this first example I am using the OVRPRTF command.
01 OVRPRTF FILE(QPQUPRFIL) DEVTYPE(*AFPDS) + TOSTMF('/MyFolder/test.pdf') WSCST(*PDF) + OVRSCOPE(*CALLLVL) 02 RUNQRY QRY(*NONE) QRYFILE((MYLIB/TESTPF)) OUTTYPE(*PRINTER)
There are three parameters in the OVRPRTF command we need to address:
Printer Device Type, DEVTYPE, need to be *AFPDS.
To Stream File, TOSTMF, contains the folder and file name I wish to save the spooled file to. In this example I will save it to the document test.pdf in the IFS folder MyFolder.
Work Stations Customization Object, WSCST, must be *PDF.
When I run the RUNQRY command, line 2, no spool file is produced. The PDF file is created in MyFolder instead. To view it you can either use the Operations Navigator or you can use the DSPLNK at the command prompt:
As I have used the asterisk after the folder name the command displays all of the files in the folder:
Display Object Links Directory . . . . : /MyFolder Type options, press Enter. 5=Display 8=Display attributes 9=Display authority Opt Object link Type Attribute Text _ test.pdf STMF
While running the above example if you receive a CPFCE01 error then Transform Services is not installed on your server.
Additional Message Information Message ID . . . . . . : CPFCE01 Severity . . . . . . . : 40 Message type . . . . . : Escape Date sent . . . . . . : DD/DD/DD Time sent . . . . . . : TT:TT:TT Message . . . . : Required product option not available. Cause . . . . . : The function requires that product 5770TS1 option 01 be available to use. Recovery . . . : Use the Check Product Option (CHKPRDOPT) command to verify that product 5770TS1 option 01 has been properly installed on the system. Correct the error and try the request again.
In my second example I am copying an existing spool file to my folder as a PDF file:
CPYSPLF FILE(QPQUPRFIL) TOFILE(*TOSTMF) + SPLNBR(*LAST) + TOSTMF('/MyFolder/test_1.pdf') WSCST(*PDF) + STMFOPT(*REPLACE)
The same parameters in the CPYSPLF command, TOSTMF, WSCST, STMFOPT, have to be completed as in the previous example. And in the To File, TOFILE, the value *TOSTMF is given as I am copying the spool file to a stream file.
If you do not have Transform Services on your server you can still copy spool files to the IFS as a TIF (TIFF) file using the Work Stations Customization Object, WSCST, QWPTIFFG4, see below:
01 OVRPRTF FILE(QPQUPRFIL) DEVTYPE(*AFPDS) + TOSTMF('/MyFolder/test_1.tif') + WSCST(QWPTIFFG4) OVRSCOPE(*CALLLVL) 02 RUNQRY QRY(*NONE) QRYFILE((DEVSRC)) OUTTYPE(*PRINTER)
The TIF is not as nice as the PDF, but it is better than nothing.
You can learn more about these from the IBM web site:
This article will only work for IBM i 6.1 and 7.1.
I have received several communications informing me that you can use the Operation Navigator to convert a spool file to a PDF file.
The above post was to describe how to create a PDF file from a spool file without human intervention, for example: part of a day-end process.