• 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
    Focal Point Solutions Group

    A CloudSAFE Company

    The Power of Services:
    IBM Cloud and Managed Solutions

    Upgrade your business processes, and save time and resources with specialized, best-in-class IT solutions.

    Managed, Cloud, and Custom Solutions

    Managed Services

    • Infrastructure Monitoring & Management
    • Server Patching
    • Application Patching
    • Managed Backup
    • High Availability/Disaster Recovery Monitoring
    • Cloud Environment Monitoring
    • Office 365 Management
    • Endpoint Management
    • Managed Colocation

    Cloud Infrastructure

    • IBM i Private Cloud
    • IBM AIX Private Cloud
    • VMware Private Cloud
    • VMware Cloud Director
    • Multi-Tenant Cloud
    • Desktop as a Service

    Data Protection & High Availability

    • Disaster Recovery as a Service
    • Backup as a Service
    • IBM i Vaulting

    Security

    • Security Consulting
    • Remote Security Awareness Training & Education
    • Onsite Security Awareness Training & Education
    • Phishing Tests
    • Penetration Tests
    • Mail Security
    • Managed Detection & Response
    • Managed Firewall
    • Endpoint Protection
    • Vulnerability Management
    • Vendor Risk Assessments
    • Security Risk Assessments

    Professional Services

    • Server Virtualization
    • Data & Infrastructure Migrations
    • Hardware & Software Installation
    • Microsoft Office 365 Implementation & Migration
    • Infrastructure Assessments
    • IBM i Consulting
    • IBM AIX Consulting

    Focal Point provides all the tools you need to protect your data, ensure the integrity of your IT infrastructure, and keep your business running.

    Contact Focal Point to Learn More About Our IBM Solutions and Partnerships

    Follow us on LinkedIn

    focalpointsg.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

  • IBM i Development and Modernization is Getting A Fresche Start with Some Ground-Breaking Subscriptions
  • CloudSAFE And Focal Point Solutions Group Combine Services, Unify Brands
  • Guru: Partitioning Result Sets Using SQL
  • As I See It: Elusive Connections
  • IBM i PTF Guide, Volume 25, Number 47
  • AWS Inks Deal With Connectria To Have a Power Play
  • IBM i Shops Have Alternatives to Db2 Web Query
  • Eradani Lays Waste to API Payload Restrictions
  • Four Hundred Monitor, November 15
  • Old PHP and Other PASE Apps Break on IBM i 7.5

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 © 2023 IT Jungle