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.

25 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
  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 4: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

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.