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


Creating PDFs With Transform Services

Add a Simple Interactive Interface

That took care of our own application requirements, but then we got to thinking that it might be nice to have a relatively easy interactive way to produce PDFs from spooled files just for our own ad hoc use. While we already use the iSphere RDi plug-in for producing PDFs from spooled files, we thought it would be nice (and fairly easy) to have a simple green-screen interface as well.

So we first created a command interface to a CL program that would take the spooled file details along with a directory name. Our command was written to detect whether it was running on V6.1 (in which case it uses the two-step copy option we used in our application) or V7.1 or later (it uses the simpler direct CPYSPLF interface). For our use, we decided we’d typically want to put the PDFs into a special directory in the IFS, so we created that directory and made it the default entry for the parameter for the command. Our CL program generates the PDF file name by appending the current timestamp to the spool file name. We did that because it was a simple way to be fairly certain the file name would be unique in the directory, avoiding the potential problem of duplicate file names. There are obviously many other ways—much better and more sophisticated ones—to accomplish this. We just chose that as a simple option.

The CL program that is the CPP for our CRTPDF command is included in Code Sample 1 and the command description is in Code Sample 2. A word of warning: our CL and CMD programming skills are more than a little rusty, so we’re sure there are better ways to do some of the things we’ve done here. Some of the code used to determine the release we’re running on and some error handling code has been omitted here to make it easier to focus on the code specifically related to creating the PDFs. Instructions for getting the complete program are included later.

We quickly discovered, however, that it was a bit painful to key in all those spooled file parameter details (the spool file name and number and fully qualified job ID). That’s when we decided that what we really wanted was a list interface similar to WRKSPLF (Work with Spooled Files) that had an option to create a PDF. The thought of coding such a utility on our own seemed like it would take a lot more time than we wanted to devote to it. But we had a look around to see if someone out there may have already created such an interface that we might fairly easily hook into to add our PDF conversion.

That’s when we ran into the JCRSPLF command and supporting programs written by Craig Rutledge as part of his JCRCMDS set of utilities. Craig makes his source code available and we had a look at it and decided it had everything we needed as a base for our PDF conversion option.

For purposes of simplicity and focus in this article, we’re working with a version of Craig’s code where all the procedures called—which are normally located in a service program—were internalized so that we only needed one RPG source member. Craig’s code does all the heavy lifting; he’s created a very fast and useful subfile interface that brings up a list of spooled files with selection criteria similar to WRKSPLF and with many options similar to WRKPSPLF.

All we had to do was place our own option—we called it "P=Make PDF"—as one of the options at the top of the display file and insert the logic into the RPG program to invoke our command when someone enters that option on the screen. It was as simple as copying the logic from one of Craig’s other options and modifying it. It simply prompts for the CRTPDF command we had previously created, plugging in all the details of the spooled file where the option was used. The SpoolString variable, which Craig had already created and used for several other options in the utility, supplied all those details. Craig’s f_System procedure executes our command with prompting, which gives the user a chance to override our default directory for the PDF. That part of the code looks like the code in Code Sample 3 and a picture of the screen with our new option is shown in Figure 1.


We created this version of Craig’s utility as an exercise and for our own use to make it easier to create PDFs on the fly. Feel free to use what we’ve done here as an example of how you may create something of your own. If we were doing this interface for real, we would certainly have put in many more bells and whistles and better error handling. As an example, we don’t currently do any checking to ensure the directory entered via the command exists or even if it’s formatted properly; we simply make the bold assumption that it will end with a / and we append the file name to it. A validation program for our command could have taken care of details like that.

For those of you wondering why we didn’t use the latest and greatest RPG coding options, such as free format data and procedure declarations, remember that our command was already set up to work on either V6 or V7 so this program had to be compiled targeting V6.1 to exploit that flexibility. Sadly, that meant that we actually had to take on a painful task to convert some nice already free-format declarations back to fixed format to make that work!

If you’d like to take a look at the rest of the code, you can download it here. A little of the code is ours but most of it is the handiwork of Craig Rutledge, to whom we are very grateful for making it so easy to add in a little of our own functionality to his command.

We also strongly recommend that you do yourself a favor and see what other great utility programs Craig has available for download at The PDFSPLF program that we modified for the interface for our PDF generation command is a simplified version of his JCRSPLF command. That’s just one of dozens of utilities you can download and use as is or as a base for some of your own tool-building.

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