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:
DSPLNK OBJ('/MyFolder/*') |
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.
Update
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.
Its very useful..Thanks for sharing!!
ReplyDeleteThanks for lightening on unknown feature :)
ReplyDeleteI use this tool extensively to generate PDF instead of a spool file...but I believe the tool for taking an existing spool file and copying it to PDF only exists in 7.1
ReplyDeleteGreat post. You'll save folks a lot of money on 3rd party software.
ReplyDeleteThank you. Very nice. Just using this way to generate PDF. The new for me was de CPYSPLF, Thanks again.
ReplyDeleteThank you very much.
ReplyDeleteJust a question - How (if at all) do I get it to convert Hebrew characters ?
TIA.
If you can generate a spool file with Hebrew characters I do not see why this would not work.
DeleteI cannot put my hand on my heart and say for sure as the servers I have access to only have the US-English character set.
I couldn't see it either, but the fact is that it happened.
DeleteIf I could attach some screen prints' I'd show you.
The problem seems to be that the CPYSPLF doesn't have code page parameters....
Check you have PTF 5761TS1 loaded.
DeleteI tried to convert a spool file with Hebrew characters on V7R3 and it worked OK. The same for creating a PDF document from a physical file containing Hebrew characters.
DeleteI can verify the copy doesn't work at V6R1, but you can circumvent that. I have a physical file with a 133 record length on my box that I've been using to copy spool files in for different reasons. Using that file this worked.
ReplyDelete> CPYSPLF FILE(QPQUPRFIL) TOFILE(PFSPLF) JOB(459531/KEVIN/QPADEV0003) CTLCH
AR(*FCFC)
1788 records copied to file PFSPLF in KEVIN.
> OVRPRTF FILE(QSYSPRT) DEVTYPE(*AFPDS) CTLCHAR(*FCFC) TOSTMF('/kevin/test1
23.pdf') WSCST(*PDF) OVRSCOPE(*JOB)
> CPYF FROMFILE(PFSPLF) TOFILE(QSYSPRT)
1788 records copied from member PFSPLF.
> DLTOVR FILE(QSYSPRT) LVL(*JOB)
When I use the OVRPRTF command (V6R1) there is not a TOSTMF or WSCST prompt. Do you know what I need to do to make these available on the command?
DeleteSimon,
ReplyDeleteYou are great!!!
Thanks
CPYSPLF TOFILE(*TOSTMF) is not available in V6R1
ReplyDeletePaul thank you bring this to my attention.
DeleteDarn it. All these posts are developed and tested on servers running IBM i 7.1 .
I do not have access to a server with 6.1, and made a mistake here assuming that the CPYSPLF would be unchanged.
Just create a printer (if you have client access) and its print queue.Set the printer to use any print to PDF program (I use Bullzip). Then move output to this printer queue.I have using this since V5R4 and it still works in V7R1.
ReplyDeleteI use this sequence:
ReplyDelete- CPYSPLF CTLCHAR(*PRTCTL).TOFILE(X)
- With my program I explode *PRTCTL characters in the file Y
- CPYTOIMPF to copy file in IFS
- Call a script PHP to create PDF and send email
V5R4
ReplyDeleteI recently discovered the use of "Mail Tags" [STRPAGGRP and ENDPAGGRP] in AFPDS
and by using the powere of PSF and a Printer User Exit Program to split a Letter Spool File [10,000 letters] into named individual PDF files on the IFS.
this info is great, After reading this I tried it and it worked beautiful
ReplyDeleteI have been using SQL statement in CLLE programs for the past couple of years and they are great. The only caution is that we use the RUNSQLSTM instead of RUNSQL beuase our current version of HAWKEYE cross reference tool does not recognize the RUNSQL command.
ReplyDeleteThe trick is not in making the PDF out of the spool file, but in placing the resulting PDF in a network directory after the creation... ideas?
ReplyDeleteYou could map the IFS folder as a network drive on the users' PCs.
DeleteUse the /QNTC file system.
DeleteTOSTMF('/QNTC/ComputerName/ShareName/FileName.pdf')
Above article is good to a created PDF. However when I follow exact steps to convert Arabic content and transfer PDF it to my PC, I see Arabic as junk in the PDF. Any suggestions please....?
ReplyDeleteHaving a problem when I copy the spool file to pdf with overlay. The variable data converts fine, but on the overlay, the fonts are changed and the sizes specified in the *OVL file are ignored. I have checked and we have all ptf's installed. Any ideas?
ReplyDeletesimon, you are really great i really appreciate you
ReplyDeleteJust now reading this thread... For IBM i 6.1, it should be noted that CPYSPLF does not have TOSTMF() nor WSCST(), however OVRPRTF does have both parameters. The implication is that a process must initially create the spooled file into the IFS rather than making a later copy with CPYSPLF.
ReplyDeletehi, good article. But I have a problem.
ReplyDeleteI get CPFCE01 error and when I check it with CHKPRDOPT PRDID(5761TS1) OPTION(01) I get NO ERRORS DETECTED BY CHKPRDOPT. what I do?
From IBM's Suport documents:
Delete<< CPFCE01: Required product option not available.
Cause: The function requires that product 5761TS1 option 01 be available to use.
Recovery: Use the Check Product Option (CHKPRDOPT) command to verify that product 5761TS1 option 01 has been properly installed on the system. >>
I would ask for 5761TS1 to be installed again.
DeleteVery helpful article Simon! ACS also has a feature to download spool files as PDF. Thanks!
ReplyDeleteThat is great to know.
DeleteI use the method described above in batch jobs, and then send the PDF as an email attachment using SNDSMTPEMM.
Of course. Once you have the PDF in the IFS you can copy it anywhere you desire.
DeleteMap the IFS folder as a network drive on your PC. Then you can drag-and-drop it anywhere you want, or double click on the file to open it.
DeleteI love this page
ReplyDeleteGot anything in regards to printing a PDF file from a network folder from an RPGLE and/or CL program?
ReplyDeleteAn existing PDF file?
DeleteOr one created by the RPGLE/CL programs?
existing. TIFF files as well. Need to incorporate along with traditional spool files
DeleteIPDS and PCL printers, no AFP
DeleteHave you tried what is suggested here...
Deletehttp://www-01.ibm.com/support/docview.wss?uid=nas8N1011519
no we have not. will review and see if we have all the IBM pieces to the puzzle.
Deletewill do my best to let you know any out come
Actually if you just define a printer emulation session and set the device to Microsoft PDF printer it'll create a PDF that can be e-mailed.
ReplyDeleteI am not so sure that would work in most scenarios I use this for as they are batch jobs that run as part of the night run.
DeleteIs there a way to format margins? This works great, but it would be nice to pad the document with white space.
ReplyDeleteYou would need to add the "margins" to the spool file.
DeleteYou can either specify it on the OVRPRTF or if the spooled file is only meant for PDF, you can specify it on the CRTPRTF. Here is one of my printer files that will print to PDF in portrait mode and save it in my home directory:
DeleteCRTPRTF FILE(MYLIB/MYPRTF)
SRCFILE(MYLIB/QDDSSRC)
SRCMBR(MYPRTF)
DEVTYPE(*AFPDS)
PAGESIZE(11 8.5 *UOM)
LPI(6)
CPI(15)
FRONTMGN(0.5 0.5)
OVRFLW(45)
UOM(*INCH)
TOSTMF('Credit Card Authorizations Approved.pdf')
WSCST(*PDF)
REPLACE(*YES)
I am generating my file that is sent directly to the printer. Is there a way to send it there AND a copy to the IFS? It seems to disappear before the CPYSPLF executes.
ReplyDeleteThe default action after a spool file is printed is that it is deleted.
DeleteThw way I get around it is to change the spool file to SAVE(*YES), or override the spool file in your program to do the same.
Can you ftp a PDF file?
ReplyDeleteOf course you can.
DeleteHere is an example.
Hi Simon, I've been away from development for nearly 15 years and I'm having a hard time getting to the IFS with command on the iSeries. I'm on 7.2. In i Navigator, I can see the /mystuff/file1.pdf but when I try on the iSeries, it's not found. I need to ftp what is in /mystuff to a server downstream in an automated batch job. Can't seem to get it to work. I'm using user id with special permission *ALLOBJ
Delete*AUDIT
*IOSYSCFG
*JOBCTL
*SAVSYS
*SECADM
*SERVICE
*SPLCTL
so I know it is not a permission issue.
Any help would greatly appreciated as I'm DESPERATE!
I would use FTP to perform a "ls" to get a list of the contents of that folder. If it is not seen then IMHO it is probably a security issue.
DeleteChange the permission to the file to *ALL & check again.