Pages

Wednesday, March 26, 2014

Creating PDF files from spool files

ovrprtf cpysplf pdf transform services

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.

52 comments:

  1. Thanks for lightening on unknown feature :)

    ReplyDelete
  2. I 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

    ReplyDelete
  3. Great post. You'll save folks a lot of money on 3rd party software.

    ReplyDelete
  4. Thank you. Very nice. Just using this way to generate PDF. The new for me was de CPYSPLF, Thanks again.

    ReplyDelete
  5. Thank you very much.
    Just a question - How (if at all) do I get it to convert Hebrew characters ?
    TIA.

    ReplyDelete
    Replies
    1. If you can generate a spool file with Hebrew characters I do not see why this would not work.

      I 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.

      Delete
    2. I couldn't see it either, but the fact is that it happened.
      If I could attach some screen prints' I'd show you.
      The problem seems to be that the CPYSPLF doesn't have code page parameters....

      Delete
    3. Check you have PTF 5761TS1 loaded.

      Delete
    4. I 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.

      Delete
  6. I 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.

    > 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)

    ReplyDelete
    Replies
    1. 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?

      Delete
  7. Simon,

    You are great!!!

    Thanks

    ReplyDelete
  8. CPYSPLF TOFILE(*TOSTMF) is not available in V6R1

    ReplyDelete
    Replies
    1. Paul thank you bring this to my attention.

      Darn 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.

      Delete
  9. 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.

    ReplyDelete
  10. I use this sequence:
    - 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

    ReplyDelete
  11. V5R4
    I 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.

    ReplyDelete
  12. this info is great, After reading this I tried it and it worked beautiful

    ReplyDelete
  13. I 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.

    ReplyDelete
  14. William Washington III, MBAApril 8, 2014 at 6:20 PM

    The 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?

    ReplyDelete
    Replies
    1. You could map the IFS folder as a network drive on the users' PCs.

      Delete
    2. Use the /QNTC file system.
      TOSTMF('/QNTC/ComputerName/ShareName/FileName.pdf')

      Delete
  15. 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....?

    ReplyDelete
  16. Having 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?

    ReplyDelete
  17. simon, you are really great i really appreciate you

    ReplyDelete
  18. Just 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.

    ReplyDelete
  19. hi, good article. But I have a problem.
    I get CPFCE01 error and when I check it with CHKPRDOPT PRDID(5761TS1) OPTION(01) I get NO ERRORS DETECTED BY CHKPRDOPT. what I do?

    ReplyDelete
    Replies
    1. From IBM's Suport documents:

      << 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. >>

      Delete
    2. I would ask for 5761TS1 to be installed again.

      Delete
  20. Very helpful article Simon! ACS also has a feature to download spool files as PDF. Thanks!

    ReplyDelete
    Replies
    1. That is great to know.

      I use the method described above in batch jobs, and then send the PDF as an email attachment using SNDSMTPEMM.

      Delete
    2. Of course. Once you have the PDF in the IFS you can copy it anywhere you desire.

      Delete
    3. Map 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.

      Delete
  21. I love this page

    ReplyDelete
  22. Got anything in regards to printing a PDF file from a network folder from an RPGLE and/or CL program?

    ReplyDelete
    Replies
    1. An existing PDF file?
      Or one created by the RPGLE/CL programs?

      Delete
    2. existing. TIFF files as well. Need to incorporate along with traditional spool files

      Delete
    3. IPDS and PCL printers, no AFP

      Delete
    4. no we have not. will review and see if we have all the IBM pieces to the puzzle.
      will do my best to let you know any out come

      Delete
  23. 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.

    ReplyDelete
    Replies
    1. I 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.

      Delete
  24. Is there a way to format margins? This works great, but it would be nice to pad the document with white space.

    ReplyDelete
    Replies
    1. You would need to add the "margins" to the spool file.

      Delete
    2. You 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:
      CRTPRTF 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)

      Delete
  25. 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.

    ReplyDelete
    Replies
    1. The default action after a spool file is printed is that it is deleted.

      Thw 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.

      Delete
  26. Can you ftp a PDF file?

    ReplyDelete
    Replies
    1. 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
      *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!

      Delete
    2. 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.
      Change the permission to the file to *ALL & check again.

      Delete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.