You are currently on IBM Systems Media’s archival website. Click here to view our new website.


Creating PDFs With Transform Services

PDF for printed reports is the preferred format in many environments. We were working on a project recently with a requirement to produce both spooled file reports as well as PDF versions of those same reports. We’d used some other code for converting spool files to PDFs in years past but since we had heard about the system support for producing PDFs we thought we’d try out this new Transform Services mechanism. We’ve found in our travels that a lot of RPGers have yet to hear about this support—or at least haven’t had a chance to use it yet—so we thought we’d document our first foray into producing PDFs this way. The good news is that it turned out to be much easier than we had anticipated!

We had a couple of other wrinkles in our requirements for this application. First, due to the variety of systems targeted for distribution for this code, we had to support IBM i 6.1, so we couldn’t use the new CPYSPLF support in IBM i 7.1. Second, when we produced the PDF version, there was a further requirement that we had to be able to merge several reports together into a single PDF. As it turned out, both of these issues were addressed by the same solution.

The original V6.1 support for Transform Services was oriented to programs that wanted to produce a PDF instead of a spooled file. We actually needed to produce both. Granted, we could always have run each report twice—once targeting PDF and once targeting spooled files—but that just didn’t seem right. And if we’d done it that way, we still had the issue of how to merge multiple PDFs into a single one, which didn’t seem like a simple task.

So we set out to discover if there was a simple way to either merge multiple spooled files into one and/or to use the Transform Services support at V6.1 to easily convert existing spooled files to PDF format. As it turns out, we could deal with both of those with just a few steps in CL.

Even V6.1 doesn’t have the CPYSPLF support directly (which came via PTF in V7.1), we did find that we could do it indirectly. We simply needed to use CPYSPLF to copy from the spooled file to a physical file (specifying that the print control characters be included), create a printer file specifying the use of Transform Services and then use CPYF to copy the report data back to the printer file and—voila!—a PDF was produced.

What about our requirement to merge multiple reports together? Since we were copying to a physical file already, we found that we could simply copy multiple spooled files to the same physical file to merge them before we did the transform to PDF. It really couldn’t get much simpler!

So the basics of our approach looked something like this in CL:

             CRTPF      FILE(QTEMP/HOLDSPLF) RCDLEN(134) TEXT('Temp file +
                          to hold splf data for PDF conversion'))

           /* CPYSPLF to be repeated for each spooled file to be merged */      

                          JOB(&JOBNBR/&JOBUSR/&JOBNAME) SPLNBR(&SPLFNBR) +
                          MBROPT(*Add) CTLCHAR(*FCFC)   

                          Prtf to use Transform Svcs for PDF') +
                          CTLCHAR(*FCFC) TOSTMF(&IFSFILE) WSCST(*PDF)


The Details

Simple as it is, let’s look at some of the details. First, we had to create a physical file to hold the spooled file data temporarily. Since we needed it to contain all the spooled file data and the extra control information, we needed to make sure the record length was at least 1 character longer than the spooled file report(s).

Next, we used CPYSPLF (Copy Spooled File) to copy all the data to our physical file, specifying CTLCHAR(*FCFC) to include the printer control characters. Remember that we also needed to merge multiple spooled files together, so our actual logic included a loop containing the CPYSPLF command and we specified MBROPT(*Add) so that each spooled file was appended to the end of the file. For simplicity, we’ve omitted that extra looping logic as well as the logic to retrieve the spooled file info used in the command.

Rather than override an existing printer file to include the Transform Services parameters for PDF conversion, we decided to simply create a temporary printer file (CRTPRTF). A few details are important to note about this step.

  1. The Transform Services support requires that the printer file be TYPE(*AFPDS).
  2. To specify that we want PDF output instead of a spooled file, we use the Workstation Customization Object (WSCST) value of *PDF.
  3. The use of WSCST requires a companion parameter value in To Stream File (TOSTMF). Note that the TOSTMF value may contain either a directory name or a file name. Any directory included must already exist, but the file name (if included) must not exist.
  4. As with the CPYSPLF command earlier, we need to specify on the CPYF command that the printer file will use the control characters from the physical file - CTLCHAR(*FCFC)

There are some limitations to the support for Transform Services and there are also some prerequisites. First, you must have the Transform Services product installed. It’s free and included as part of a “bonus pack” included with V6.1 and V7.1. For V6.1, it is product 5761TS1 and for V7.1 and V7.2, it is product 5770TS1. You need both the base and Option 1 parts installed.

In addition, those products themselves have prerequisites of Option 33 (PASE) of the IBM i operating system and option 3, which includes support for the IFS. Other details and hints for installing and using Transform Services for PDF can be found in this IBM document.

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Like what you just read? To receive technical tips and articles directly in your inbox twice per month, sign up for the EXTRA e-newsletter here.



2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters