midrange.com code scratchpad
Name:
Arco Simonse
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
05/03/2016 07:52:06 pm
IP:
Logged
Description:
Pdf to spool conversion throug qshell / ghostscript / rfile.
Code:
  1. --------------------------- Begin script ------------------------------
  2. #!/QOpenSys/usr/bin/sh
  3. #
  4. #
  5. # Script: pdf2pcl2outq.sh
  6. # pdf2pcl2outq.sh converts a PDF file (input.pdf) to PCL,
  7. # temporarily stores this output file into a unique .pcl file,
  8. # then copies PCL to qgpl/qprint (you can change in script).
  9. #
  10. # Derived from YIPS example.
  11. #
  12. # Install (example IFS /home/abc, but any dir will do):
  13. # > ftp this script to IFS file pdf2pcl2outq.sh (binary ftp)
  14. # call qp2term
  15. # > cd /home/abc
  16. # > chmod +x pdf2pcl2outq.sh
  17. # Note: /home/abc is just an example directory.
  18. #
  19. # Usage (example IFS /home/abc, but any dir will do):
  20. # 1) interactive command:
  21. # QSH CMD('/home/abc/pdf2pcl2outq.sh /home/abc/input.pdf SPLNAM QUSRSYS/PRT01 1')
  22. # 2) batch command:
  23. # SBMJOB CMD(QSH CMD('/home/abc/pdf2pcl2outq.sh /home/abc/input.pdf SPLNAM QUSRSYS/PRT01 1'))
  24.  
  25. # export necessary environment settings
  26. export QIBM_DESCRIPTOR_STDIN=CRLN=N
  27. export QIBM_QSH_CMD_OUTPUT=NONE
  28.  
  29. # IBM i print PCL info
  30. PCL="pxlmono"
  31. OFLE="qprint"
  32. ODVT="*userascii"
  33. OHLD="*no"
  34. OVR="ovrprtf file($OFLE) outq($3) drawer($4) devtype($ODVT) rplunprt(*no) splfname($2) hold($OHLD)"
  35.  
  36. # help
  37. if [ $# -ne 4 ]; then
  38.   echo "Usage: `basename $0` input.pdf spoolname outqlib/outq drawer" 1>&2
  39.   exit 1
  40. fi
  41.  
  42. # Create a unique job and timestamp combination
  43. # Start with the numeric date in ISO type format
  44. d=$(date +%Y-%m-%d-%H-%M-%S)
  45. # get the job number
  46. j=$(getjobid -s | cut -c -6)
  47. # append them all together to get a single unique filename
  48. sid=$d\_$j
  49.  
  50. # run ghostscript convert pdf to pcl
  51. echo "ghostscript writing to pcl device $PCL"
  52. which gs
  53. echo "gs -q -dNOPAUSE -dSAFER -sOutputFile=/tmp/$sid -sDEVICE=$PCL $1"
  54. gs -q -dNOPAUSE -dSAFER -sOutputFile=/tmp/$sid -sDEVICE=$PCL $1
  55.  
  56. # pcl to outq
  57. echo "cat /tmp/$sid | Rfile -wbQ -c "$OVR" $OFLE"
  58. cat /tmp/$sid | Rfile -wbQ -c "$OVR" $OFLE
  59. echo "SPOOLJOBID:"$(getjobid -s)
  60.  
  61. # delete the temporary file
  62. rm /tmp/$sid
  63.  
  64. --------------------------- End script --------------------------------
  65.  
  66. --------------------------- Begin rpg code ----------------------------
  67.       //------------------------------------------------------------------//
  68.       //
  69.       //  Program      : CVTPDFSPLR
  70.       //  Description  : PDF to Spool conversion via QSHELL.
  71.       //                 Conversion is done via the pdf2pcl2spl script.
  72.       //                 The spoolfile id is retrieved by the use of
  73.       //                 the UNIXCMD tool (thanks to Scott Klement)
  74.       //                 which allows us to retrieve qshell response
  75.       //                 data via rpg special file pipe.
  76.       //
  77.       //  Compile      : crtbndrpg
  78.       //  ActGrp       : *NEW
  79.       //------------------------------------------------------------------//
  80.   
  81.       // Compiler opties
  82.  
  83.      h dftactgrp(*NO)
  84.      h option(*NODEBUGIO:*SRCSTMT)
  85.   
  86.      funix      cf   f 1000        special pgmname('UNIXCMD')
  87.      f                                     plist(unixparm) usropn
  88.   
  89.  
  90.       // main program *entry
  91.      d CVTPDFSPLR      PI
  92.      d  peFileIn                   1024A
  93.      d  peSpoolName                  10A
  94.      d  peOutqLib                    10A
  95.      d  peOutq                       10A
  96.      d  peDrawer                      7A
  97.      d  peJobName                    10A
  98.      d  peJobUser                    10A
  99.      d  peJobNbr                      6A
  100.      d  peSplNbr                      6P 0
  101.      d  pePdf2SplPgm                 30A
  102.  
  103.      d wwQualOutq      S             21A
  104.      d PDF2SPL_ROOT...
  105.      d                 C                   '/home/abc/'
  106.  
  107.      d cmd             s           5000A
  108.      d record          s           1000A
  109.      d pos0            s             10I 0
  110.      d pos1            s             10I 0
  111.      d pos2            s             10I 0
  112.      d tmpJobNo        s              6P 0
  113.      d wwPdf2SplPgm    S             30A
  114.  
  115.      IUNIX      NS
  116.      I                                  1 1000  Record
  117.  
  118.      C     UNIXPARM      PLIST
  119.      C                   PARM                    CMD
  120.       /free
  121.        *inlr = *on ;
  122.  
  123.        if %trim(pePdf2SplPgm) <> *blanks ;
  124.          wwPdf2SplPgm = pePdf2SplPgm ;
  125.        else ;
  126.          // default PCL script
  127.          wwPdf2SplPgm = 'pdf2pcl2outq.sh' ;
  128.        endif ;
  129.  
  130.        cmd = PDF2SPL_ROOT    + %trim( wwPdf2SplPgm )
  131.                              + ' ' + %trim( peFileIn )
  132.                              + ' ' + %trim( peSpoolname )
  133.                              + ' ' + %trim( wwQualOutQ )
  134.                              + ' ' + %trim( peDrawer ) + x'00' ;
  135.  
  136.        open UNIX;
  137.  
  138.        dow '1' ;
  139.          read UNIX;
  140.          if %eof(UNIX);
  141.            leave ;
  142.          endif ;
  143.          if %scan( 'SPOOLJOBID:' : record ) > 0 ;
  144.            pos0 = %scan( ':' : record ) ;
  145.            pos1 = %scan( '/' : record ) ;
  146.            pos2 = %scan( '/' : record : pos1 + 1 ) ;
  147.            if pos0 <> 0 and pos1 <> 0 and pos2 <> 0 ;
  148.              peJobName = %subst( record : pos2 + 1 : 10 ) ;
  149.              peJobUser = %subst( record : pos1 + 1 : pos2 - pos1 - 1 ) ;
  150.              tmpJobNo  = %dec(%subst( record
  151.                                     : pos0 + 1
  152.                                     : pos1 - pos0 - 1 )
  153.                              : 6 : 0 ) ;
  154.              // But jobnumber of the spoolfile is always 1 lower than
  155.              // the reported jobnbr, because of the spawning in qshell.
  156.              if tmpJobNo <> 1 ;
  157.                tmpJobNo = tmpJobNo - 1 ;
  158.              else ;
  159.                tmpJobNo = 999999 ;
  160.              endif ;
  161.              peJobNbr = %editc( tmpJobNo : 'X' ) ;
  162.              peSplNbr  = 1 ;
  163.            endif ;
  164.          endif ;
  165.        enddo ;
  166.  
  167.        return ;
  168.       /end-free
  169.  
  170. --------------------------- End rpg code ------------------------------
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css