• 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
    ARCAD Software

    [Webinar] Trends for 2026: ARCAD Software’s strategic vision

    Between the acceleration of artificial intelligence, constant pressure to modernize existing systems, and ever-increasing security requirements, 2026 is shaping up to be a decisive year for legacy platforms.

    At the start of this new year, this webinar offers strategic insight into the future of these critical environments, which are at the heart of information systems.

    Join Philippe Magne, CEO of ARCAD Software, as he shares his analysis of the major trends and structural issues facing organizations:

    • DevSecOps: What are the current trends in DevOps transformation?
    • Generative artificial intelligence: What are the concrete use cases and measurable benefits for application development and maintenance?
    • Critical application security: How to respond to growing and sophisticated threats?
    • Cloud and hybridization: How do legacy applications fit into current cloud strategies?

    Save your seat for March 24 at 11 AM EDT!

    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

    Emulate sp_Help In DB2 For i Where Do I Find These IBM i Licensed Products?

    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

  • No Joke: Big Memory And Flash Price Hikes Coming April 1
  • Strategic Topics To Think About For 2026, Part 2
  • Guru: IBM i Job Log Detective Brings Structure To Job Log Analysis In VS Code
  • IBM Launches Hybrid Cloud Backup Product With Cobalt Iron
  • IBM i PTF Guide, Volume 28, Number 10
  • Why You Need To Think About Offsite Data Protection
  • IBM Gets Bob 1.0 Off The Ground
  • You Store The Crown Jewels In A Safe, Not In A Bucket
  • More Power Systems Withdrawals, And Some From Red Hat, Too
  • Price Increases Are Here, Or Pending, And For Sure For Memory

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