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/pdf2) 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 quit3) 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/pdfptr5) Restart scheduler:
/usr/lib/lpshut;/usr/lib/lpschedTo create a PDF file, you can use the syntax:
lp -d pdfptr <FILENAME>-for example-lp -d pdfptr /etc/hosts
request id is pdfptr-32The 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/text2postchange this to:filter=/usr/spool/lp/bin/text2post_16Copy /usr/spool/lp/bin/text2post to /usr/spool/lp/bin/text2post_16.Edit /usr/spool/lp/bin/text2post_16This 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 defchange this to:/margin 16.0000 defTo change the size of the characters, find:
/$FONT findfont 9 scalefont setfontchange this to:/$FONT findfont 5 scalefont setfontYou 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.shTo use this filter, you would use the syntax:
cat reportfile | ff_filter.sh | lp -d pdfptrNOTE: 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.ZNOTE: 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 muttWith 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/nullThis 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/