--------------------------- Begin script ------------------------------ #!/QOpenSys/usr/bin/sh # # # Script: pdf2pcl2outq.sh # pdf2pcl2outq.sh converts a PDF file (input.pdf) to PCL, # temporarily stores this output file into a unique .pcl file, # then copies PCL to qgpl/qprint (you can change in script). # # Derived from YIPS example. # # Install (example IFS /home/abc, but any dir will do): # > ftp this script to IFS file pdf2pcl2outq.sh (binary ftp) # call qp2term # > cd /home/abc # > chmod +x pdf2pcl2outq.sh # Note: /home/abc is just an example directory. # # Usage (example IFS /home/abc, but any dir will do): # 1) interactive command: # QSH CMD('/home/abc/pdf2pcl2outq.sh /home/abc/input.pdf SPLNAM QUSRSYS/PRT01 1') # 2) batch command: # SBMJOB CMD(QSH CMD('/home/abc/pdf2pcl2outq.sh /home/abc/input.pdf SPLNAM QUSRSYS/PRT01 1')) # export necessary environment settings export QIBM_DESCRIPTOR_STDIN=CRLN=N export QIBM_QSH_CMD_OUTPUT=NONE # IBM i print PCL info PCL="pxlmono" OFLE="qprint" ODVT="*userascii" OHLD="*no" OVR="ovrprtf file($OFLE) outq($3) drawer($4) devtype($ODVT) rplunprt(*no) splfname($2) hold($OHLD)" # help if [ $# -ne 4 ]; then echo "Usage: `basename $0` input.pdf spoolname outqlib/outq drawer" 1>&2 exit 1 fi # Create a unique job and timestamp combination # Start with the numeric date in ISO type format d=$(date +%Y-%m-%d-%H-%M-%S) # get the job number j=$(getjobid -s | cut -c -6) # append them all together to get a single unique filename sid=$d\_$j # run ghostscript convert pdf to pcl echo "ghostscript writing to pcl device $PCL" which gs echo "gs -q -dNOPAUSE -dSAFER -sOutputFile=/tmp/$sid -sDEVICE=$PCL $1" gs -q -dNOPAUSE -dSAFER -sOutputFile=/tmp/$sid -sDEVICE=$PCL $1 # pcl to outq echo "cat /tmp/$sid | Rfile -wbQ -c "$OVR" $OFLE" cat /tmp/$sid | Rfile -wbQ -c "$OVR" $OFLE echo "SPOOLJOBID:"$(getjobid -s) # delete the temporary file rm /tmp/$sid --------------------------- End script -------------------------------- --------------------------- Begin rpg code ---------------------------- //------------------------------------------------------------------// // // Program : CVTPDFSPLR // Description : PDF to Spool conversion via QSHELL. // Conversion is done via the pdf2pcl2spl script. // The spoolfile id is retrieved by the use of // the UNIXCMD tool (thanks to Scott Klement) // which allows us to retrieve qshell response // data via rpg special file pipe. // // Compile : crtbndrpg // ActGrp : *NEW //------------------------------------------------------------------// // Compiler opties h dftactgrp(*NO) h option(*NODEBUGIO:*SRCSTMT) funix cf f 1000 special pgmname('UNIXCMD') f plist(unixparm) usropn // main program *entry d CVTPDFSPLR PI d peFileIn 1024A d peSpoolName 10A d peOutqLib 10A d peOutq 10A d peDrawer 7A d peJobName 10A d peJobUser 10A d peJobNbr 6A d peSplNbr 6P 0 d pePdf2SplPgm 30A d wwQualOutq S 21A d PDF2SPL_ROOT... d C '/home/abc/' d cmd s 5000A d record s 1000A d pos0 s 10I 0 d pos1 s 10I 0 d pos2 s 10I 0 d tmpJobNo s 6P 0 d wwPdf2SplPgm S 30A IUNIX NS I 1 1000 Record C UNIXPARM PLIST C PARM CMD /free *inlr = *on ; if %trim(pePdf2SplPgm) <> *blanks ; wwPdf2SplPgm = pePdf2SplPgm ; else ; // default PCL script wwPdf2SplPgm = 'pdf2pcl2outq.sh' ; endif ; cmd = PDF2SPL_ROOT + %trim( wwPdf2SplPgm ) + ' ' + %trim( peFileIn ) + ' ' + %trim( peSpoolname ) + ' ' + %trim( wwQualOutQ ) + ' ' + %trim( peDrawer ) + x'00' ; open UNIX; dow '1' ; read UNIX; if %eof(UNIX); leave ; endif ; if %scan( 'SPOOLJOBID:' : record ) > 0 ; pos0 = %scan( ':' : record ) ; pos1 = %scan( '/' : record ) ; pos2 = %scan( '/' : record : pos1 + 1 ) ; if pos0 <> 0 and pos1 <> 0 and pos2 <> 0 ; peJobName = %subst( record : pos2 + 1 : 10 ) ; peJobUser = %subst( record : pos1 + 1 : pos2 - pos1 - 1 ) ; tmpJobNo = %dec(%subst( record : pos0 + 1 : pos1 - pos0 - 1 ) : 6 : 0 ) ; // But jobnumber of the spoolfile is always 1 lower than // the reported jobnbr, because of the spawning in qshell. if tmpJobNo <> 1 ; tmpJobNo = tmpJobNo - 1 ; else ; tmpJobNo = 999999 ; endif ; peJobNbr = %editc( tmpJobNo : 'X' ) ; peSplNbr = 1 ; endif ; endif ; enddo ; return ; /end-free --------------------------- End rpg code ------------------------------