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

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    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

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

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