Technical article 128000

Can I create a printer that generates PDF documents?

OpenServer Definitive 2018UnixWare 7 Definitive 2018OpenServer 6UnixWare 7

Written · Last revised

Problem

I would like to print a file and have a PDF document generated.

Solution

This task can be accomplished by creating a PostScript
printer which converts the postscript data to PDF using
the ps2pdf ghostscript utility.  This can be done by
following these steps:
1) Create a directory to store the PDF files:
   mkdir /var/pdf
   chown lp:lp /var/pdf
2) Create an HPNP style PostScript printer with /usr/lib/hpnp/hpnpcfg
   /usr/lib/hpnp/hpnpcfg
    choose option 6 - Add a printer
       printer name -- pdfptr
       peripheral name  (hit return)
         (ignore error about unknown peripheral)
   (For UnixWare, hit return for all additional options)
       model script -- postscript
       spooler class -- (hit return)
    choose q to quit

3) Replace the HPHPF script with script to convert to pdf. Replace /usr/spool/lp/admins/lp/interfaces/pdfptr with these contents:

#!/bin/sh
MODEL=`basename $0`
REALMODEL=`echo $0 | sed -e "s%$MODEL%model.orig/$MODEL%"`
$REALMODEL "$@" | ps2pdf  -  "/var/pdf/${1}.pdf"
4) For UnixWare systems only (OpenServer systems skip this step):
   lpadmin -p pdfptr -I postscript -T PS-b
   cp /etc/lp/model/PS /etc/lp/interfaces/model.orig/pdfptr
5) Restart scheduler:
   /usr/lib/lpshut;/usr/lib/lpsched

To create a PDF file, you can use the syntax:

lp -d pdfptr <FILENAME>
-for example-
lp -d pdfptr /etc/hosts
request id is pdfptr-32

The PDF file will be in the /var/pdf/ directory, in this case it would be /var/pdf/pdfptr-32.pdf

NOTE:     To modify the pdfptr to handle wider reports, you can edit the
          file /usr/spool/lp/admins/lp/interfaces/model.orig/pdfptr and
          find the line:
filter=/usr/spool/lp/bin/text2post
change this to:
filter=/usr/spool/lp/bin/text2post_16
Copy /usr/spool/lp/bin/text2post to /usr/spool/lp/bin/text2post_16.
Edit /usr/spool/lp/bin/text2post_16
This filter converts the text file to postscript and sets values
that control the margins, size of the font and size of page.
These can be changed to handle a wider document.  In the file
/usr/spool/lp/bin/text2post_16, find the function port_head(),
Inside this function, find:
/margin 36.0000 def
change this to:
/margin 16.0000 def

To change the size of the characters, find:

/$FONT findfont 9 scalefont setfont
change this to:
/$FONT findfont 5 scalefont setfont
You can make the page accept more lines per page in the
port_proc()   function, find:
(line>65)       { line=0; print "Page" }
change this to:
(line>85)       { line=0; print "Page" }
The text2post_16 script also looks for ^L type form feeds, but
it wants them to be at the beginning of the line.  If you have
form feeds which are not at the beginning of the line, you could
use a pre-filter, to change the position of the ^L character.  For
this you could use a script similar to this ff_filter.sh:
#!/bin/sh
input=$1
OLD_IFS="$IFS"
IFS='
'
cat $input|while read line
do
  case $line in
    *^L*) pt1=`echo $line|awk -F^L '{print $1}'`
          pt2=`echo $line|awk -F^L '{print $2}'`
          echo "$pt1"
          echo "^L"
          echo "$pt2";;
     *) echo "$line";;
  esac
done
IFS="$OLD_IFS"
The ^L characters need to be <CTRL><L> and not ^ L, so
cut & paste of this script will not work properly without edits.
IFS is being set to a carriage return only, don't include any
spaces.  For your convenience a copy of this ff_filter.sh is also
available on our ftp site at:
ftp://ftpput.sco.com/tmp/support/ff_filter.sh

To use this filter, you would use the syntax:

cat reportfile | ff_filter.sh | lp -d pdfptr
NOTE:     OpenServer 5 customers who have removed CUPS will need the
          CUPS libraries for the ps2pdf ghostscript utility.  These are
          available separately from our ftp site at:
          ftp://ftpput.sco.com/tmp/support/cups_libs.tar.Z
NOTE:     This script can be modified further to email the PDF files to
          the user that submitted the script.  Using MUTT for the mailer
          is better for mailing attachments.  MUTT can be installed from
          Skunkware using patchck:
/etc/patchck mutt

With MUTT installed, you could append these lines to the end of the /usr/spool/lp/admins/lp/interfaces/pdfptr script:

PATH=$PATH:/usr/local/bin
USER=$2
mutt -s "$1 PDF report" -a "/var/pdf/${1}.pdf" $USER < /dev/null

This will mail the PDF file as a mime encoded attachment to the user that submitted the print job. If the user has an external email address, you could setup a ~/.forward file for that user with the user's external email address to have the file sent externally. This assumes that your email services are setup and working.

See also

http://osr600doc.xinuos.com/en/DSK_gscript/Ps2pdf.htm TA110966 How can I configure OpenServer to print to a file? TA127294 How to print to a file using CUPS? TA125337 I want to create a script or use the command line to send an email with an attachment non-interactively, how can I do this? http://www.sco.com/skunkware/

From the Xinuos technical article database, record 128000. Reproduced with permission. The original is at www.sco.com/ta/128000, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.