View Single Post
  #1   (View Single Post)  
Old 20th December 2017
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,507
Default PDF/Postscript -> print filter -> Print Queue Filter

The cups-filters pkg README has instructions to use a foomatic-rip with a ppd. The instructions advise the use of a2ps, or enscript, I believe that a2ps detects postscript files and passes them on to the printer while txt files are converted to *.ps on their way to the printer. One thing I have noticed is that /etc/a2ps.cfg has entries to also generate postscript out of a pdf. For me, printing a pdf from the command line does not work with a2ps.

The FreeBSD handbook has a "Smart Filters" example that will call enscript if a postscript file is not detected: the first 4 characters of a postscript file are
Quote:
%!PS"
The first 4 characters of a pdf file are
Quote:
%PDF
so I thought the Smart Filter could be expanded to detect a pdf and filter it through pdftops print/poppler. I modified the script provided by W. Block to detect pdf files and hopefully convert to postscript.

The last piece of this is that I predominately use 2 print queues: lp: simplex letter and duplex: duplex letter. Both queues work when I use evince/xpdf/gv/pdftops but I get an "undefined command h operand stack" printed out with the following:
/usr/local/libexec/print_filter
Code:
#!/bin/sh
#
#  print_filter - Print PostScript, PDF or plain text on a PostScript printer
#
IFS="" read -r first_line
first_four_chars=`expr "$first_line" : '\(....\)'`

case "$first_four_chars" in
%!PS)
    echo "$first_line" && cat && exit 0
    exit 2
    ;;
%PDF)
    ( echo "$first_line"; cat ) | /usr/local/bin/pdftops - | && exit 0
    exit 2
    ;;
*)
    ( echo "$first_line"; cat ) | /usr/local/bin/enscript -o - && exit 0
    exit 2
    ;;
esac
/usr/local/libexec/br_script_duplex
Code:
#!/bin/sh

/usr/local/libexec/print_filter | \
 /usr/local/bin/foomatic-rip --ppd \
 /etc/foomatic/direct/Brother-HL-5450DN_BR-Script3-Postscript-Brother-en.ppd \
 -o PageSize=Letter -o Duplex=DuplexNoTumble
My older pcl5e printer would detect *ps, *pdf and *txt with a ghostscript filter. What is the best way to pipe the output from print_filter -> queue filter? Is it acceptable to use scripts sequentially? I could create pdf/pdf-duplex and txt print queues but it seems less elegant.

Last edited by shep; 21st December 2017 at 12:08 AM.
Reply With Quote