Wednesday, December 8, 2021

Converting a spool file with bar code to PDF

copy sool file with bar code to ifs

I keep getting asked this question: If I generate a spool file with a bar code in it and I copy it to PDF will the bar code still display?

I wrote about copying spool files to PDF in the IFS in March 2014. What I am going to describe here is based on that post.

If the people who ask the question had read that post they would have discovered how simple this is.

Let me start with the externally described printer file, as I have not used Output specifications for prints in nigh on 30 years. The printer file's definition only needs two lines:

01 A          R TESTLINE                  SKIPB(001)
02 A            TESTDATA      10A       10BARCODE(CODE3OF9)

Line 1: The printer record format definition.

Line 2: I am going to generate a Code 3 of 9 barcode. There is no reason I chose this as opposed to the many others that are available.

When the printer file is compiled it must be compiled with the "Printer device type", DEVT, as *AFPDS.

                      Create Printer File (CRTPRTF)

Type choices, press Enter.

File . . . . . . . . . . . . . . FILE      > PRTFILE   
  Library  . . . . . . . . . . .           >   MYLIB     
Source file  . . . . . . . . . . SRCFILE   > DEVSRC    
  Library  . . . . . . . . . . .           >   MYLIB     
Source member  . . . . . . . . . SRCMBR      *FILE     
Generation severity level  . . . GENLVL      20    
Flagging severity level  . . . . FLAG        0     
Device:                          DEV
  Printer  . . . . . . . . . . .             *JOB      
Printer device type  . . . . . . DEVT      > *AFPDS     ← Here

The RPG program is similarly simple.

01  **free
02  dcl-f PRTFILE printer ;

03  TESTDATA = '1234567890' ;

04  write TESTLINE ;

05  *inlr = *on ;

Line 2: Definition of the printer file, PRTFILE.

Line 3: Some value is moved to the barcode's field.

Line 4: The record format is written.

Line 5: And I am done.

There are two easy ways to copy the generated spool file to the IFS as PDF.

I prefer this first way as it does not generate a spool file in IBM i, it generates the PDF directly.

01  PGM



06            DEVTYPE(*AFPDS) +
07            TOSTMF(&PATH) +
08            WSCST(*PDF) +
09            OVRSCOPE(*CALLLVL)



Line 2: I need to specify the path name in more than once place so I define a variable to contain it, rather than repeat is more than once.

Lines 3 and 4: I delete the PDF file if it is present in the IFS folder.

Lines 5 – 9: I override the printer file, PRTFILE, to have the attributes I need: *AFPDS and *PDF.

Line 10: I call the program, PRTFPGM, to generate the "spool file", but there is not one as the PDF is generate directly.

When I open the "Integrated File System" tool in ACS I can find the PDF file in my folder.

And when I open that file I can see the barcode.

The other method I have used is to copy an existing spool file to the IFS.

01  PGM


04            TOFILE(*TOSTMF) +
05            SPLNBR(*LAST) +
06            TOSTMF('/home/RPGPGM/barcode.pdf') +
07            WSCST(*PDF) +
08            STMFOPT(*REPLACE)


Line 2: This time the program to generate the spool file is called first.

Lines 3 – 8: I use the Copy Spool File command, CPYSPLF, to copy the spool file to a PDF in my folder.

The disadvantage of this method is that as a spool file is generated it will need to be deleted.


Yes, it is that simple.


If the above does not work you need to go to the original post I wrote in 2014, here, and check if the required license program is installed.


This article was written for IBM i 7.4, and should work for some earlier releases too.

1 comment:

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.