• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • PDF = Pretty Darn Fine!

    April 30, 2014 Ted Holt

    If you’re running IBM i 6.1 or later, you have a great alternative to spooled files at your disposal–PDF. Here are four easy ways to add PDF generation to your programming.

    Method 1: Write directly to PDF.

    You can make your RPG (or COBOL or whatever) programs write directly to PDF stream files. You’ll need to specify the proper values in the Create Printer File (CRTPRTF), Change Printer File (CHGPRTF), or Override with Printer File (OVRPRTF) commands:

    • Device type (DEVTYPE) must be *AFPDS
    • Workstation customizing object (WSCST) must be *PDF
    • To stream file (TOSTMF) must have a valid directory or stream file name

    If you specify a directory, the system will invent a name for the generated stream file. If you specify a stream file name, that stream file must not exist at run time.

    By way of example, consider a simple report. First, create the printer to generate a PDF.

     * To create:
     *
     *  CRTPRTF FILE(MYLIB/QAD03320P)
     *          SRCFILE(MYLIB/QDDSSRC) SRCMBR(QAD03320P)
     *          DEVTYPE(*AFPDS) +
     *          TOSTMF('/tmp/Customer-list.PDF') WSCST(*PDF)
    
    A                                      REF(QCUSTCDT)
    A          R DETAIL                    SPACEB(1)
    A            CUSNUM    R              1
    A            LSTNAM    R             +1
    A            INIT      R             +1
    A            CITY      R             +1
    

    Write an RPG program to build the report.

    Fqcustcdt  if   e             disk
    Fqad03320p o    e             printer
    
     /free
         *inlr = *on;
         dow '1';
            read cusrec;
            if %eof();
               leave;
            endif;
            write detail;
         enddo;
         return;
    

    Voila!

    Method 2: Copy a spooled file to PDF.

    Use the Copy Spooled File (CPYSPLF) command to copy a spooled file to PDF. I have used this technique with both SCS and AFPDS spooled files.

    Specify *TOSTMF in the TOFILE parameter. The TOSTMF and WSCST parameters behave as in CRTPRTF. You may specify STMFOPT(*REPLACE) to build a new stream file over an existing stream file of the same name.

    CPYSPLF FILE(QPRTLIBL) TOFILE(*TOSTMF) SPLNBR(*LAST) +
               TOSTMF('Some-report.pdf') WSCST(*PDF)
    

    Method 3: A Slightly Longer Way to Copy a Spooled File to PDF.

    I’m told that Method 2 does not work under IBM i 6.1. Since I’ve never worked at 6.1, I’m not sure. Here’s a variation on the previous method.

    This method is slightly longer. It requires you to copy the spooled file to a temporary database file, and from there to a stream file. Notice the use of first-character forms control.

    CRTPF   QTEMP/REPORT RCDLEN(133)
    CPYSPLF FILE(QPRINT01) TOFILE(QTEMP/REPORT) +
               SPLNBR(*LAST) CTLCHAR(*FCFC)
    OVRPRTF FILE(QSYSPRT) DEVTYPE(*AFPDS) CTLCHAR(*FCFC) +
               TOSTMF('test-report.pdf') WSCST(*PDF)
    CPYF    FROMFILE(QTEMP/REPORT) TOFILE(QSYSPRT)
    

    One big disadvantage of this method is that it only handles SCS spooled files.

    Method 4: Read and reformat the spooled file.

    The previous methods all produce PDFs that look like the reports. If you’re willing to read the report, you can reformat it any way you like. Here’s an RPG program that reads a spooled file and builds a stream file.

    FSpoolIn   if   f  136        disk    usropn
    FSpoolOut  o    f  132        printer oflind(*inof)
    F                                     prtctl(prtctlds)
    F                                     usropn
    
    D prtctlds        ds            15
    D  pSpaceBefore           1      3
    D  pSpaceAfter            4      6
    D  pSkipBefore            7      9
    D  pSkipAfter            10     12
    D  pLineNbr              13     15
    
    D OutputData      ds           132
    
    D InputDS         ds
    D   sSkipBefore           1      3
    D   sSpaceBefore          4      4
    D   InputData             5    136
    
     /free
         *inlr = *on;
         open SpoolIn  ;
         open SpoolOut;
         dow '1';
            read SpoolIn InputDS;
            if %eof();
               leave;
            endif;
    
            OutputData = InputData;
    
            // make changes to OutputData as desired
    
            if sSkipBefore <> *blanks;
               pSkipBefore = sSkipBefore;
            else;
               pSkipBefore = *blanks;
            endif;
    
            if sSpaceBefore <> *blanks;
               %subst(pSpaceBefore:3:1) = sSpaceBefore;
            else;
               pSpaceBefore = *blanks;
            endif;
    
            write SpoolOut OutputData;
         enddo;
         return;
    

    Here’s the CL that drives it.

    pgm
    
          dcl  &Stmf    *char    40   '/tmp/My-library-list.PDF'
    
          crtprtf qtemp/spoolout devtype(*afpds) +
                     tostmf(&Stmf) wscst(*pdf)
    
          clrpfm qtemp/spoolin
          monmsg cpf3142 exec(do)
             crtpf qtemp/spoolin rcdlen(136)
          enddo
    
          cpysplf  file(qprtlibl) tofile(qtemp/spoolin) +
                      job(*) splnbr(*last) mbropt(*add) +
                      ctlchar(*prtctl)
    
    /* Delete the stream file if it exists. */
          rmvlnk objlnk(&Stmf)
          monmsg cpfa0a9
    
          ovrdbf  spoolin tofile(qtemp/spoolin)
          call    qad03321r
          dltovr  spoolin
    
    endpgm
    

    The program reads a database file into which a spooled file has been copied and writes to a stream file. This version uses a printer control data structure to control spacing and skipping.

    There you have it. If you want to integrate PDF into your programming, you can easily do so. If this is a topic you’d like to explore further, check out some of the links below.

    RELATED STORIES

    Converting a Spooled File to PDF

    Transform Services

    The CVT2PDF Utility



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    New Generation Software

    FREE Webinar:

    Creating Great Data for Enterprise AI

    Enterprise AI relies on many data sources and types, but every AI project needs a data quality, governance, and security plan.

    Wherever and however you want to analyze your data, adopting modern ETL and BI software like NGS-IQ is a great way to support your effort.

    Webinar: June 26, 2025

    RSVP today.

    www.ngsi.com – 800-824-1220

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Valence Framework for IBM i:  Download Valence 4.0 FREE! Web and mobile apps for IBM i.
    LANSA:  Webinar: Mobile and the IBM i: Why Should You Care? May 21, 9 am PT/11 am CT/Noon ET
    COMMON:  Join us at the COMMON 2014 Annual Meeting & Exposition, May 4 - 7 in Orlando, Florida

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Unions Criticize IBM’s Earning Per Share Focus IBM i 7.2 Available May 2

    Leave a Reply Cancel reply

Volume 14, Number 10 -- April 30, 2014
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Bug Busters Software Engineering

Table of Contents

  • Emulate sp_Help In DB2 For i
  • PDF = Pretty Darn Fine!
  • Where Do I Find These IBM i Licensed Products?

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle