Discussion:
printcap configuration problem
Beeblebrox
2014-07-18 09:34:04 UTC
Permalink
Hi.

Cups has been borked for some time, so I must use lpd. Several problems when
configuring /etc/printcap however. So far what I have:

1 HP2100tn:rm=192.168.1.9:rp=RAW1:\
2 :sd=/var/spool/lpd/hp2100:lf=/var/log/lpd-errs:\
3 :if=/usr/local/libexec/lf2crlf:\
4 :mx#0:sh:

The Problems:
* Line 1 fails completely with "lpr: lp: unknown printer" when using any
name other than "lp". Tried:
NO: HP2100tn:lp=***@192.168.1.9:rm=HP2100tn:\
NO: HP2100tn:lp=***@192.168.1.9:\
WORKS: lp:lp=***@192.168.1.9:rm=HP2100tn:\
WORKS: lp:rm=192.168.1.9:rp=RAW1:\

* I need to specify below options. Placing in /etc/printcap (line 1) as
lp;r=300x300;q=draft;c=gray;p=a4;m=auto:\
:rm=192.168.1.9:rp=RAW1:\
results in the same "unknown printer" error. I need to either find the
correct syntax for printcap or I could modify /usr/local/libexec/lf2crlf,
which has:
#!/bin/sh
CR=$'\r'
/usr/bin/sed -e "s/$/${CR}/g"

## will A4 size info here work?
#page_width=
#page_height=
#border=

Printer: HP LaserJat 2100, PS-level-2



-----
FreeBSD-11-current_amd64_root-on-zfs_RadeonKMS
--
View this message in context: http://freebsd.1045724.n5.nabble.com/printcap-configuration-problem-tp5929730.html
Sent from the freebsd-questions mailing list archive at Nabble.com.
Warren Block
2014-07-18 12:07:01 UTC
Permalink
Post by Beeblebrox
Hi.
Cups has been borked for some time, so I must use lpd. Several problems when
1 HP2100tn:rm=192.168.1.9:rp=RAW1:\
2 :sd=/var/spool/lpd/hp2100:lf=/var/log/lpd-errs:\
3 :if=/usr/local/libexec/lf2crlf:\
* Line 1 fails completely with "lpr: lp: unknown printer" when using any
WORKS: lp:rm=192.168.1.9:rp=RAW1:\
"lp" is the default printer name. To use another name, that name must
be given to lpr with -P: lpr -PHP2100tn

Multiple names can be given to a single printer, so one way to get
Post by Beeblebrox
* I need to specify below options. Placing in /etc/printcap (line 1) as
lp;r=300x300;q=draft;c=gray;p=a4;m=auto:\
These are CUPS options. Standard lpd does not understand them.
Post by Beeblebrox
:rm=192.168.1.9:rp=RAW1:\
results in the same "unknown printer" error. I need to either find the
correct syntax for printcap or I could modify /usr/local/libexec/lf2crlf,
#!/bin/sh
CR=$'\r'
/usr/bin/sed -e "s/$/${CR}/g"
## will A4 size info here work?
#page_width=
#page_height=
#border=
The page size does not have anything to do with the printer name.
Unless you're trying to set up multiple names that do different things,
which can be useful.
Post by Beeblebrox
Printer: HP LaserJat 2100, PS-level-2
Beeblebrox
2014-07-18 13:10:27 UTC
Permalink
Thanks guys.

I had read several sources (including Warren's) when I finally broke down
like a little girl and had to ask for insight.
You can also define $PRINTER (for example in /etc/csh.cshrc globally) with
the name of the printer.
I had never read about this and it never ocurred to me before - thanks.
As you guessed, I was not using "lpr -P hp2100"
These are CUPS options. Standard lpd does not understand them.
Well a day's work wasted there...
Or apsfilter options.
Hence the idea of modifying my existing /usr/local/libexec/lf2crlf to define
the desired printer settings, since appsfilter is a collection of filter
files, AFAIK?

I had already read in man printcap that one must use <px - page.pwidth, py -
page.plength> (in pixels) as page size. However considering that I have
print/papersize-default-a4 installeed, there should be a simpler way to
define it as default rather than px/py in printcap?

Also, I do not find any way of defining resolution (r=), quality (q=) and
orieantation (m=) in printcap, and the job ends up using the default printer
settings (excluding the a4 parameter which is sent from host) - so I
logically come back to the filter file...

Thanks for the help.



-----
FreeBSD-11-current_amd64_root-on-zfs_RadeonKMS
--
View this message in context: http://freebsd.1045724.n5.nabble.com/printcap-configuration-problem-tp5929730p5929805.html
Sent from the freebsd-questions mailing list archive at Nabble.com.
Polytropon
2014-07-18 23:51:49 UTC
Permalink
Post by Beeblebrox
You can also define $PRINTER (for example in /etc/csh.cshrc globally) with
the name of the printer.
I had never read about this and it never ocurred to me before - thanks.
As you guessed, I was not using "lpr -P hp2100"
Just set $PRINTER and never worry again. :-)
Post by Beeblebrox
These are CUPS options. Standard lpd does not understand them.
Well a day's work wasted there...
No, you have learned something, so it has not been wasted.
Post by Beeblebrox
Or apsfilter options.
Hence the idea of modifying my existing /usr/local/libexec/lf2crlf to define
the desired printer settings, since appsfilter is a collection of filter
files, AFAIK?
Yes. I've been using apsfilter in the past, but it seems that
it doesn't receive much more development work. On the other hand,
CUPS has become _the_ standard for printing, sometimes even
required as a dependency even when it's not needed at all.
Programs rely on its presence much more than on the system's
provided spooling and filtering interfaces, so using it often
is the only chance to get "mainstream software" working, whereas
other, "un-normal" software keeps working with whatever is there.
Post by Beeblebrox
I had already read in man printcap that one must use <px - page.pwidth, py -
page.plength> (in pixels) as page size. However considering that I have
print/papersize-default-a4 installeed, there should be a simpler way to
define it as default rather than px/py in printcap?
Those settings should be better put into the printer filter or
its configuration. This is what CUPS manages independently.
But you can also do this with your own filter if it doesn't
have much to do.

This is an example of how I have been working (outside of CUPS),
the /opt/libexec/ps2pcl-dup.sh filter:

#!/bin/sh
/usr/bin/printf "\033&k2G" || exit 2
/usr/local/bin/gs -q -dBATCH -dNOPAUSE -dPARANOIDSAFER \
-dSAFER -sPAPERSIZE=a4 -r600x600 \
-sDEVICE=ljet4d -dDuplex=true \
-sOutputFile=- - && exit 0
exit 2

You can see that I've been using gs (ghostscript) with the options
defining the required paper size (ISO A4) and resolution (600 dpi).
The printer driver used by gs is "ljet4d" which works with the
HP LaserJet 4000 DN I'm still using. In most cases, it doesn't
even matter which printer driver you specify as long as it's
"halfway compatible" (here: works for many PCL-based printers).

The printer filter (script) doesn't do much more than process
the input from the application which is printing, usually PS,
obtained via standard input, to become the output desired, sent
to standard output. The mechanism of /etc/printcap makes sure
the data arrives at the correct point (network IP or name, maybe
with a specified port number, or a parallel or USB connector).

Having those means separated makes troubleshooting and testing
quite easy. You can use netcat (nc) to feed output directly to
the printer, or > it into the /dev/whatever directly. You can
examine the (intermediate) printer data or temporarily change
the destination.
Post by Beeblebrox
Also, I do not find any way of defining resolution (r=), quality (q=) and
orieantation (m=) in printcap, and the job ends up using the default printer
settings (excluding the a4 parameter which is sent from host) - so I
logically come back to the filter file...
Those are usually defined _in_ or _for_ the printer filter. CUPS
manages those sufficiently well. The web interface is slow to use,
but if you can get used to it, changing parameters is easy. There
are also configuration files located in /usr/local/etc/cups, and
finally there's lpadmin.
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Warren Block
2014-07-19 00:44:03 UTC
Permalink
Post by Polytropon
This is an example of how I have been working (outside of CUPS),
#!/bin/sh
/usr/bin/printf "\033&k2G" || exit 2
/usr/local/bin/gs -q -dBATCH -dNOPAUSE -dPARANOIDSAFER \
-dSAFER -sPAPERSIZE=a4 -r600x600 \
-sDEVICE=ljet4d -dDuplex=true \
-sOutputFile=- - && exit 0
exit 2
You can see that I've been using gs (ghostscript) with the options
defining the required paper size (ISO A4) and resolution (600 dpi).
The printer driver used by gs is "ljet4d" which works with the
HP LaserJet 4000 DN I'm still using.
The LJ4000 is a PostScript printer. The trick of modifying the incoming
PS file to set the page size will be faster. Here, gs has to build and
send a multi-megabyte bitmap.
Post by Polytropon
Post by Beeblebrox
Also, I do not find any way of defining resolution (r=), quality (q=) and
orieantation (m=) in printcap, and the job ends up using the default printer
settings (excluding the a4 parameter which is sent from host) - so I
logically come back to the filter file...
Those are usually defined _in_ or _for_ the printer filter. CUPS
manages those sufficiently well. The web interface is slow to use,
but if you can get used to it, changing parameters is easy. There
are also configuration files located in /usr/local/etc/cups, and
finally there's lpadmin.
These can also be set by having the filter modify the PostScript file.
Polytropon
2014-07-19 15:13:46 UTC
Permalink
Post by Warren Block
Post by Polytropon
This is an example of how I have been working (outside of CUPS),
#!/bin/sh
/usr/bin/printf "\033&k2G" || exit 2
/usr/local/bin/gs -q -dBATCH -dNOPAUSE -dPARANOIDSAFER \
-dSAFER -sPAPERSIZE=a4 -r600x600 \
-sDEVICE=ljet4d -dDuplex=true \
-sOutputFile=- - && exit 0
exit 2
You can see that I've been using gs (ghostscript) with the options
defining the required paper size (ISO A4) and resolution (600 dpi).
The printer driver used by gs is "ljet4d" which works with the
HP LaserJet 4000 DN I'm still using.
The LJ4000 is a PostScript printer.
In fact, it has many personalities, PS is one of them. It also
handles PCL, and additionally ASCII. Therefore it has a multiple
personality disorder, but that's actually fine, because each of
them has its advantage.

Personalities can be selected at the operator panel of the printer.
Setting AUTO usually causes the correct output to appear.
Post by Warren Block
The trick of modifying the incoming
PS file to set the page size will be faster. Here, gs has to build and
send a multi-megabyte bitmap.
I found that using PS directly is slower than using gs, but I'm
going with this solution with just works (TM) for many years now.
The reason might be that I also had other printers in the same
location (HP Laserjet 4, Lexmark Optra something, Kyocera FS-600)
which all understand the gs-generated data without me having to
change anything. That's a very lazy man's solution, I know. :-)

Currently I'm using CUPS with a PPD file, so I think things are
kept in PS the whole way (PPD used to modify PS).
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Warren Block
2014-07-19 15:47:31 UTC
Permalink
Post by Polytropon
Post by Warren Block
Post by Polytropon
This is an example of how I have been working (outside of CUPS),
#!/bin/sh
/usr/bin/printf "\033&k2G" || exit 2
/usr/local/bin/gs -q -dBATCH -dNOPAUSE -dPARANOIDSAFER \
-dSAFER -sPAPERSIZE=a4 -r600x600 \
-sDEVICE=ljet4d -dDuplex=true \
-sOutputFile=- - && exit 0
exit 2
You can see that I've been using gs (ghostscript) with the options
defining the required paper size (ISO A4) and resolution (600 dpi).
The printer driver used by gs is "ljet4d" which works with the
HP LaserJet 4000 DN I'm still using.
The LJ4000 is a PostScript printer.
In fact, it has many personalities, PS is one of them. It also
handles PCL, and additionally ASCII. Therefore it has a multiple
personality disorder, but that's actually fine, because each of
them has its advantage.
Personalities can be selected at the operator panel of the printer.
Setting AUTO usually causes the correct output to appear.
They can also be selected with PJL, but I agree that Auto usually does
fine.
Post by Polytropon
Post by Warren Block
The trick of modifying the incoming
PS file to set the page size will be faster. Here, gs has to build and
send a multi-megabyte bitmap.
I found that using PS directly is slower than using gs, but I'm
going with this solution with just works (TM) for many years now.
It somewhat depends on what generates the PostScript file. Some
applications render a big bitmap and then convert that to PostScript,
which makes it bigger and loses the resolution-independent advantages.
Real PS programs are usually much smaller than the equivalent bitmaps.

If the printer can handle PCL6, it might be faster that ljet4 (PCL5) due
to bitmap compression. The gs driver is pxlmono.
Bernt Hansson
2014-07-18 12:58:08 UTC
Permalink
Post by Warren Block
Post by Beeblebrox
* I need to specify below options. Placing in /etc/printcap (line 1) as
lp;r=300x300;q=draft;c=gray;p=a4;m=auto:\
These are CUPS options. Standard lpd does not understand them.
Or apsfilter options.
Warren Block
2014-07-18 13:31:43 UTC
Permalink
Post by Warren Block
Post by Beeblebrox
* I need to specify below options. Placing in /etc/printcap (line 1) as
lp;r=300x300;q=draft;c=gray;p=a4;m=auto:\
These are CUPS options. Standard lpd does not understand them.
Or apsfilter options.
Yes. Or they could be used by a custom filter, although I've never
bothered, just using single-purpose filters and setting up multiple
print queues for different tasks.
Beeblebrox
2014-07-18 15:40:33 UTC
Permalink
Just an idea that I'd like to test if possible:

Is there a way to parse a cups/ppd/*ppd file for lpd? So, for example
/usr/local/libexec/lf2crlf (or any "if" file) maybe I would change to

#!/bin/sh
sed/awk /usr/local/etc/cups/ppd/HP_LaserJet_2100.ppd

This is to test what is brıken in cups - the ppd (unlikely) or cups.

Regards.




-----
FreeBSD-11-current_amd64_root-on-zfs_RadeonKMS
--
View this message in context: http://freebsd.1045724.n5.nabble.com/printcap-configuration-problem-tp5929730p5929887.html
Sent from the freebsd-questions mailing list archive at Nabble.com.
Warren Block
2014-07-18 15:55:48 UTC
Permalink
Post by Beeblebrox
Is there a way to parse a cups/ppd/*ppd file for lpd? So, for example
/usr/local/libexec/lf2crlf (or any "if" file) maybe I would change to
#!/bin/sh
sed/awk /usr/local/etc/cups/ppd/HP_LaserJet_2100.ppd
This is to test what is br?ken in cups - the ppd (unlikely) or cups.
Technically, sure. A program can check the PPD for printer features,
then enable or configure those features according to settings in
printcap or other files. That is one of the things that CUPS does.

In practice, it may be somewhat involved. Unless you change models of
printers frequently, it is probably easier to just manually set up the
filter to do what is desired.
Polytropon
2014-07-18 23:19:46 UTC
Permalink
Post by Warren Block
In practice, it may be somewhat involved. Unless you change models of
printers frequently, it is probably easier to just manually set up the
filter to do what is desired.
An existing printer configuration can be used to create
a new one, or a variation (for example the same printer
with and without duplex, or the use of tray 2, 3 or 4
instead of the default -> different printers to the
system, so it's easy to select features according to
the printer name). This can be done with individual
printer filters (for PS + adding features like paper
format definition, duplex or tray selection; PS to
PCL; PS to Splix or whatever you need) stored as
individual files. The use of $PRINTER makes it easy
to switch the default printer - /etc/printcap doesn't
need to be modified and "rebuilt" (cap_mkdb).

For example, I have those:

/opt/libexec/ps2pcl-dup.sh
/opt/libexec/ps2pcl-nodup.sh
/opt/libexec/ps2splix.sh

They correspond to "Laserjet" (default per $PRINTER),
"Laserjet-nodup", and "Samsung". The really fantastic
thing is that you can name the printers as you wish,
representing brand, model, features, or even location.
:-)
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Martin Alejandro Paredes Sanchez
2014-07-28 05:14:19 UTC
Permalink
El Fri, 18 Jul 2014 08:40:33 -0700 (PDT)
Post by Beeblebrox
Is there a way to parse a cups/ppd/*ppd file for lpd? So, for example
/usr/local/libexec/lf2crlf (or any "if" file) maybe I would change to
#!/bin/sh
sed/awk /usr/local/etc/cups/ppd/HP_LaserJet_2100.ppd
This is to test what is brıken in cups - the ppd (unlikely) or cups.
Regards.
foomatic can process the PPD file

***@morena ~ > pkg info foomatic-filters
foomatic-filters-4.0.17_1
Name : foomatic-filters
Comment : Foomatic wrapper scripts
Description :
Filter scripts used by the printer spoolers to convert the incoming
PostScript data into the printer's native format using a
printer/driver specific, but spooler-independent PPD file.

WWW: http://www.openprinting.org
Beeblebrox
2014-08-02 08:05:14 UTC
Permalink
Post by Martin Alejandro Paredes Sanchez
foomatic can process the PPD file
Thanks - I already had Foomatic installed. Like Cups, Foomatic also seems to
have problems on my system however:
http://freebsd.1045724.n5.nabble.com/print-cups-base-web-interface-broken-unable-to-print-tp5918098p5934106.html



-----
FreeBSD-11-current_amd64_root-on-zfs_RadeonKMS
--
View this message in context: http://freebsd.1045724.n5.nabble.com/printcap-configuration-problem-tp5929730p5934110.html
Sent from the freebsd-questions mailing list archive at Nabble.com.
Beeblebrox
2014-08-02 13:39:22 UTC
Permalink
@Warren:
Below is what I have in printcap and the filter file. psif is straight out
of the Handbook page. When printing an existing ps file with "$ /usr/bin/lpr
-Php2100", the resulting hardcopy has 3-4 lines truncated from the top - I
can't figure it out.

Secondly, I don't see the point of piping an already ps-formated file
through ghostscript, unless it's to adjust print resolution. Is gs smart
enough to recognize a ps file and simply (and quickly) modify the ink amount
or must it do a complete re-process of the page?

hp2100:lp:rm=192.168.1.9:rp=raw:\
:if=/usr/local/libexec/filters/psif:\
:lf=/var/log/lpd-errs:af=/var/spool/lpd/acct:\
:sd=/var/spool/lpd/hp2100:\
:mx=0:sh:

# psif: Print PostScript or plain text on a PostScript printer
IFS="" read -r first_line
first_two_chars=`expr "$first_line" : '\(..\)'`

case "$first_two_chars" in
%!)
# %! : PostScript job, print it.
echo "$first_line" && cat && exit 0
exit 2
;;
*)
# otherwise, format with enscript
( echo "$first_line"; cat ) | /usr/local/bin/enscript -o - && exit 0
exit 2
;;
esac




-----
FreeBSD-11-current_amd64_root-on-zfs_RadeonKMS
--
View this message in context: http://freebsd.1045724.n5.nabble.com/printcap-configuration-problem-tp5929730p5934162.html
Sent from the freebsd-questions mailing list archive at Nabble.com.
Warren Block
2014-08-02 16:34:43 UTC
Permalink
Post by Beeblebrox
Below is what I have in printcap and the filter file. psif is straight out
of the Handbook page. When printing an existing ps file with "$ /usr/bin/lpr
-Php2100", the resulting hardcopy has 3-4 lines truncated from the top - I
can't figure it out.
Sorry, I don't understand the question.
Post by Beeblebrox
Secondly, I don't see the point of piping an already ps-formated file
through ghostscript, unless it's to adjust print resolution. Is gs smart
enough to recognize a ps file and simply (and quickly) modify the ink amount
or must it do a complete re-process of the page?
Ghostscript is not involved here. The first two characters of the
incoming file are read. If they are %!, it is assumed to be a
PostScript file and sent straight through. Otherwise, it is assumed to
be a plain text file, and formatted into a PostScript file with
print/enscript-[letter|a4].

Both cases are for use with a printer that understands PostScript
natively. A plain LaserJet 2100 does not, although there was a 2100m
that did, and a PS SIMM could be added to the other models.
Post by Beeblebrox
hp2100:lp:rm=192.168.1.9:rp=raw:\
:if=/usr/local/libexec/filters/psif:\
:lf=/var/log/lpd-errs:af=/var/spool/lpd/acct:\
:sd=/var/spool/lpd/hp2100:\
# psif: Print PostScript or plain text on a PostScript printer
IFS="" read -r first_line
first_two_chars=`expr "$first_line" : '\(..\)'`
case "$first_two_chars" in
%!)
# %! : PostScript job, print it.
echo "$first_line" && cat && exit 0
exit 2
;;
*)
# otherwise, format with enscript
( echo "$first_line"; cat ) | /usr/local/bin/enscript -o - && exit 0
exit 2
;;
esac
Beeblebrox
2014-08-03 05:35:13 UTC
Permalink
Post by Warren Block
Both cases are for use with a printer that understands PostScript
natively. A plain LaserJet 2100 does not,
Mine does, it's the 2100tn model, has native ps level-II
http://people.virginia.edu/~cavcomp2/printers/hp/2100/2100.htm
Post by Warren Block
Sorry, I don't understand the question.
Well, my first question was: Why under the current filter setting does lpd scrape or cut 4 lines from the top? I'm able to get the hard copy the way I want it to look by increasing the top margin by 4 lines, save it as a ps file, then lpr the file from command line.

The ghostscript comment was referring to previous discussion - sorry for the confusion: If I want to print in r: 300 x 300, the only way that's going to happen is by sending it through ghostscript, if I understand correctly? How could I modify psif so that "lpr -Php2100 -r300 somefile.ps" would result in 1. check if ps 2. adjust for one of available resolution options (300 OR 600).

I hope I was a bit better at explaining this time :)
Warren Block
2014-08-03 19:40:30 UTC
Permalink
Post by Beeblebrox
Post by Warren Block
Both cases are for use with a printer that understands PostScript
natively. A plain LaserJet 2100 does not,
Mine does, it's the 2100tn model, has native ps level-II
http://people.virginia.edu/~cavcomp2/printers/hp/2100/2100.htm
Post by Warren Block
Sorry, I don't understand the question.
Well, my first question was: Why under the current filter setting does
lpd scrape or cut 4 lines from the top? I'm able to get the hard copy
the way I want it to look by increasing the top margin by 4 lines,
save it as a ps file, then lpr the file from command line.
lpd does not mess with the input file, although the filter might. I
suspect that this just means you need to supply some margin settings for
enscript in the psif filter. See enscript(1).
Post by Beeblebrox
The ghostscript comment was referring to previous discussion - sorry
for the confusion: If I want to print in r: 300 x 300, the only way
that's going to happen is by sending it through ghostscript, if I
understand correctly?
No, that's not necessary. PostScript can be told what resolution to
use. A filter would have to append that to the start of the PS program,
similar to the way duplex can be set. See this thread for an example:
https://forums.freebsd.org/viewtopic.php?&t=40651

I have some additional filters on my list of things to add to the
Handbook, but no idea when I can work on them.
Post by Beeblebrox
How could I modify psif so that "lpr -Php2100 -r300 somefile.ps" would
result in 1. check if ps 2. adjust for one of available resolution
options (300 OR 600).
-r is already used by lpr. Actually, I have not experimented with
passing through options that way, and don't know if it can be done.
I'd just define two printers, one for 300DPI and one for 600DPI.

The header code is probably going to be
<</HWResolution[600 600]>> setpagedevice
or
<</HWResolution[300 300]>> setpagedevice

That might be different on a printer as old as the LJ2100. It can be
tested in plain PS files sent directly to the printer.
Martin Alejandro Paredes Sanchez
2014-08-08 05:57:29 UTC
Permalink
El Sun, 03 Aug 2014 08:35:13 +0300
Post by Beeblebrox
Post by Warren Block
Both cases are for use with a printer that understands PostScript
natively. A plain LaserJet 2100 does not,
Mine does, it's the 2100tn model, has native ps level-II
http://people.virginia.edu/~cavcomp2/printers/hp/2100/2100.htm
If your printer support PS, you are 90% ready,most of the programs
produce PS at the moment to print

What are you printing?
From what program?
Post by Beeblebrox
The ghostscript comment was referring to previous discussion - sorry
for the confusion: If I want to print in r: 300 x 300, the only way
that's going to happen is by sending it through ghostscript, if I
understand correctly? How could I modify psif so that "lpr -Php2100
-r300 somefile.ps" would result in 1. check if ps 2. adjust for one
of available resolution options (300 OR 600).
Careful, the command

lpr -Php2100 -r300 somefile.ps

might erase the file "somefile.ps", read the man of lpr

-r Remove the file upon completion of spooling or upon completion
of printing (with the -s option).

It does not have a option for resolution

LPR take a file and send to LPD and LPD spool the job in the spool
directory, start the FILTER to process the job and send to the printer

Since LPR only give the file to LPD
LPD only handle the queue (spool)
The FILTER is the only that can modify the job (file printed)

To send options to the filter, you can use the option -Z of lpr

-Z daemon-options
Some spoolers, such as LPRng, accept additional per-job options
using a `Z' control line. When -Z is specified, and -p (pr(1))
is not requested, the specified daemon-options will be passed to
the remote LPRng spooler.

But the filter need to take options from LPD control file (till here my
explanation, since my point is, you need to read lpr manual to know what
options can be used with lpr)

If you make a program that understand 300dpi option, you can use the
command

lpr -Php2100 -Z300dpi somefile.ps

You specify your filter (program) in the printcap file as

if=/usr/local/libexec/filters/psif

You should try apsfilter (is in ports), but I don remember that
apsfilter accept option for resolution

I am working in a input filter for LPR/LPD that accept most of CUPS
options, if you want to try, let me know

-HTH
Martin Paredes
Martin Alejandro Paredes Sanchez
2014-08-24 23:49:23 UTC
Permalink
El Tue, 19 Aug 2014 09:02:05 +0300
Hello Alejandro,
Hello Beeblebrox
* printcap setup complete, no problems. Printer supports PS level-2
That means that we can setup a PostScrip printer in this case or use
the driver "pxlmono" recommended by OpenPrinting

http://www.openprinting.org/printer/HP/HP-LaserJet_2100
* I would prefer not to install and have to learn/maintain a 3rd or
4th package to get the job done, so preferably no lprng/printtools if
I can avoid it.
That was one of my objectives, if FreeBSD has a print spool manager
LPR/LPD use it and avoid installing CUPS, LPRng
What are you printing? > From what program?
Many things put mostly ps/pdf/text.
My filter can handle this 3 formats OK
You should try apsfilter
Already using enscript.
apsfilter is an input-filter or text filter compatible with LPD
In the printcap if= identifies the input filter that will be used

Enscript converts ASCII files to PostScript, HTML, or RTF (is not a
filter), not compatible with LPD
* I need a filter where I can a) set HWresolution, and b) set pages
per sheet, like 4 pages of pdf file on one A4 sheet, landscape mode,
minimum or no margins between pages so as to minimize white space.
Let's see if we can handle this options

First, create a directory for the new spool

root# mkdir -p /var/spool/lpd/lj2100
root# chmod 770 /var/spool/lpd/lj2100
root# touch /var/spool/lpd/lj2100/filter-errors
root# touch /var/spool/lpd/lj2100/if-MAPS.MappingOptions
root# touch /var/spool/lpd/lj2100/if-MAPS.conf
root# chmod 660 /var/spool/lpd/lj2100/*
root# chown -R daemon:daemon /var/spool/lpd/lj2100

Add this entry in your /etc/printcap

lj2100|lp|HP LaserJet 2100TN:\
:tty.device=:remote.host=192.168.1.9:remote.queue=raw:\
:filt.input=/usr/local/bin/if-MAPS:\
:spool.log=/var/spool/lpd/lj2100/filter-errors:\
:spool.dir=/var/spool/lpd/lj2100:\
:max.blocks=0:banner.disable:

To validate the printacap, run:

root# chkprintcap

If there are no errors, Nothing is going to be printed to screen

This is the 1st of 4 mail
Martin Alejandro Paredes Sanchez
2014-08-25 06:18:47 UTC
Permalink
El Sun, 24 Aug 2014 16:49:23 -0700
Post by Martin Alejandro Paredes Sanchez
El Tue, 19 Aug 2014 09:02:05 +0300
* I need a filter where I can a) set HWresolution, and b) set pages
per sheet, like 4 pages of pdf file on one A4 sheet, landscape mode,
minimum or no margins between pages so as to minimize white space.
This can be accomplish using the next command

lpr -P lj2100 -Z 600dpi,nup=4,a4,landscape FileToPrint

In nUp printing, there are 2 type of margins

1.- around the whole page (The printer minimum margins on each edge)
2.- around each page on a sheet (nUpMargin in PostScript points)

lpr -P lj2100 -Z 600dpi,nup=4,a4,landscape,nupmargin=25 FileToPrint

HTH
Martin Paredes

Martin Alejandro Paredes Sanchez
2014-08-24 23:58:41 UTC
Permalink
In its content of

/var/spool/lpd/lj2100/if-MAPS.conf

put the following

#
# Values must be in lower case
#
PaperSize=a4
PaperTray=trayauto
PaperType=standard
PaperOrientation=portrait
Resolution=600x600
Duplex=off
EconoMode=on
FilterText=enscript
DuplexManual=yes
CopiesManual=yes

# Send mail upon completion
MailLog=no

# Log information
# 0 = Do not log
# 1 = log errors
# 2 = log information to user
# 3 = log trace information
LogLevel=1

#
# Configure GosthScript
# (GS_DEVICE=ps ==> Especify a PostScript printer)
GS_DEVICE=ps

# The printer has minimum margins on each edge of approximately
# 6 mm (0.25 inch). The margin is expresed in Postscript Points
# (0.25 x 72 = 18)
MarginLeft=18
MarginTop=18
MarginRight=18
MarginBottom=18
Martin Alejandro Paredes Sanchez
2014-08-24 23:53:42 UTC
Permalink
Create the file

/usr/local/bin/if-MAPS

In its content, put the following

#!/bin/sh
#
# This shell espect to be a text filter (filt.input=if capability in
# /etc/printcap) confusingly called the input filter.
#
# When LPD starts this filter program. It sets:
#
# standard input to the file to print
# standard output to the printer device (tty.device=lp capability)
# standard error append to the error logging file (spool.log=lf capability)
# current directory to the spooling directory (spool.dir=sd capability)
#   uid=1(daemon) gid=1(daemon)
#
# With the following parameters:
#
# filter-name [-c] -wWidth -lLength -iIndent -n login -h host acct-file
#
# -c appears if job submitted with "lpr -l" (print control
# characters and suppresses page breaks) (raw printing)
# width is the page width (page.width=pw capability), default 132
# length is the page length (page.length=pl capability), default 66
# indent is the amount of the indentation from "lpr -i", default 0
# login is the account name of the user printing the file
# host is the host name from which the job was submitted
# acct-file is the name of the accounting file (acct.file=af capability)
#
# This filter should exit with the following exit status:
#
# exit 0 If the filter printed the file successfully.
# exit 1 If the filter failed to print the file but wants LPD to try
# to print the file again. LPD will restart a filter if it
# exits with this status.
# exit 2 If the filter failed to print the file and does not want LPD
# to try again. LPD will throw out the file.
#
# You need the following packages installed
#
# GhostScript ghostscript-gpl GPL Postscript interpreter
# psUtils psutils-letter Utilities for manipulating PostScript documents
# Enscript enscript-letter ASCII to PostScript filter

#
# If user removes the job, LPD will send SIGINT (SIGNAL INTERRUPT)
# so trap SIGINT (and a few other signals) to clean up after ourselves.
#
# 1 HUP (hang up)
# 2 INT (interrupt)
# 15 TERM (software termination signal)
#
trap 'LogError 2 "Signal HUP traped"' 1
trap 'LogError 2 "Signal INT traped"' 2
trap 'LogError 2 "Signal TERM traped"' 15

umask -S u=rwx,g=rwx,o=
FilterName=`/usr/bin/basename "$0"`
PATH=/bin:/usr/bin:/usr/local/bin
TMPDIR=`/usr/bin/mktemp -q -d "/var/tmp/$FilterName.XXXXXX"` || ErrorTmpDir
export TEMP="$TMPDIR" TMPDIR PATH
[ -n "$TMPDIR" -a -d "$TMPDIR" ] && /usr/bin/chgrp daemon "$TMPDIR"


#
# SendMailLog: Send the logs by mail (sendmail).
#
SendMailLog() {
LogTrace "Sending logs by mail (this mail)"
{
echo "To: $User@$Host"
[ -e "$TMPDIR/ErrorFile" ] && echo "Cc: root"
echo "Subject: Logged information of print job \"$JobFile\""
echo
echo "Queue = \"$Queue\""
echo "File = \"$JobFile\""
echo
echo "Your print job was processed by the input-filter \"$FilterName\""
if [ -e "$TMPDIR/ErrorFile" ]; then
echo "During the process, an error occurred"
echo
echo "The logged error is:"
/bin/cat "$TMPDIR/ErrorFile"
else
echo "and was sent to the printer device successfully"
fi
if [ -s "$TMPDIR/DebugFile" ]; then
echo
echo "The trace/debug information is:"
echo
/bin/cat "$TMPDIR/DebugFile"
fi
echo
echo "This e-mail was sent by a program, do not respond to this message."
echo "In case of an error, contact your system administrator."
} | /usr/sbin/sendmail -oem -t
}


#
# CleanUp: Send the logs to StdError and remove temporary files.
#
CleanUp() {
[ $LogLevel -ge 1 -a -e "$TMPDIR/ErrorFile" ] && /bin/cat "$TMPDIR/ErrorFile" 1>&2
[ $LogLevel -ge 2 ] && /bin/cat "$TMPDIR/DebugFile" 1>&2
if ValueYes MailLog ; then
SendMailLog
fi
[ -n "$TMPDIR" -a -d "$TMPDIR" ] && /bin/rm -rf "$TMPDIR"
}


#
# LogInfo: Log the information message to the file "$TMPDIR/DebugFile"
#
# $1: Message to log
#
LogInfo() {
echo -e "$1" >> "$TMPDIR/DebugFile"
}


#
# LogTrace: Log the trace information to the file "$TMPDIR/DebugFile"
#
# $1: Trace information to log
#
LogTrace() {
if [ $LogLevel -ge 3 ] ; then
echo -e "$1" >> "$TMPDIR/DebugFile"
fi
}


#
# LogError: Log the message error to the file "$TMPDIR/ErrorFile"
#
# $1: Exit value to use
# $2: Error message to log
#
LogError() {
local Header

/usr/bin/touch "$TMPDIR/ErrorFile"
Header="`/bin/date -v-7d '+%Y/%m/%d %H:%M:%S'` $FilterName[$$]"
echo -e "$Header: Error printing '$JobFile', exit code $1" >> "$TMPDIR/ErrorFile"
echo -e "$Header: $2" >> "$TMPDIR/ErrorFile"
CleanUp
exit $1
}


#
# ErrorRunning: An error ocurred while transforming the print job
#
ErrorRunning() {
LogError 2 "`/bin/cat "$TMPDIR/Error"`"
}


#
# ErrorTmpDir: An error ocurred while trying to create a temporary directory
#
ErrorTmpDir() {
ProcessControlFile
LogError 1 "mktemp: Can't create temporary directory"
}


#
# ErrorFileType: The file of the print job, is of a type unsupported
#
ErrorFileType() {
LogError 2 "Unsupported file type '$FileType'"
}


#
# ErrorNotConfFile: The Queue/printer does not has a configuration file
#
ErrorNotConfFile() {
LogError 2 "Configuration file not found '$FilterName.conf'"
}


#
# ValueYes: Test a variable and inform if set to YES or NO.
#
# $1: Variable to be tested
#
ValueYes() {
local Value

eval Value=\$${1}
LogTrace "\tValueYes: $1 is set to '$Value'."
case $Value in
yes|true|on) return 0 ;;
no|false|off) return 1 ;;
*)
LogInfo "${1} is not set to YES or NO. Assuming ${1}='yes'"
return 0 ;;
esac
}


#
# Process the control file (grab variables JobFile, ZOptions).
#
ProcessControlFile() {
local PId ControlFile Line Value

{
read PId
read -r ControlFile
} < lock

Copies=0
while read -r Line; do
Value="${Line#?}"
case "$Line" in
Z*) [ -n "$TMPDIR" -a -d "$TMPDIR" ] && echo -n "$Value" > "$TMPDIR/-Z Options" ;;
M*) MailLog=yes ;;
N*) JobFile="$Value" ; : ${JobFile:=StdIn} ;;
f*) Copies=`/bin/expr $Copies + 1` ;;
0*) LogLevel=0 ; MailLog=no ; /bin/cat - > /dev/null ; CleanUp ; exit 0 ;;
esac
done < $ControlFile
if [ $Copies -ge 2 ] && ValueYes CopiesManual; then
echo "0CopiesManuallyPrinted" >> $ControlFile
fi
}


#
# ProcessOptionsFile: Validate and include options coming from a file.
#
# $1: File with options to validate and include
#
ProcessOptionsFile() {
local Option CmdOption Var Val ValidOption WidthInches HeightInches

if [ -r "$1" ]; then
Val=`/usr/bin/basename "$1"`
LogTrace "Running 'ProcessOptionsFile' file '$Val'"
/usr/bin/grep --invert-match --regexp='^#' --regexp='^$' "$1" | /usr/bin/tr ", " "\n" | /usr/bin/tr -Cd "[:alnum:]=\n." > "$TMPDIR/Options"

while read -r CmdOption; do
Option=`echo "$CmdOption"| /usr/bin/tr "[:upper:]" "[:lower:]"`
case "$Option" in
custom.*|papersize=custom.*)
ValidOption="PaperSize=custom"
Val=${Option##papersize=}
Val=${Val##custom.}
case "$Val" in
*x*in) Val=${Val%*in} ; Var=1 ;;
*x*mm) Val=${Val%*mm} ; Var=25.4 ;;
*x*) Var=72 ;;
*) ValidOption='' ;;
esac
if [ -n "$ValidOption" ]; then
WidthInches=`echo -n "$Val" | /usr/bin/cut -d 'x' -f 1`
HeightInches=`echo -n "$Val" | /usr/bin/cut -d 'x' -f 2`
WidthInches=`echo "scale=2; $WidthInches / $Var" | /usr/bin/bc`
HeightInches=`echo "scale=2; $HeightInches / $Var" | /usr/bin/bc`
if [ "${WidthInches}" = "0" -o "${HeightInches}" = "0" ] ; then
ValidOption=''
else
PaperSizeInches="${WidthInches}x${HeightInches}"
fi
fi ;;
*=*)
Var=`echo -n "$Option" | /usr/bin/cut -d '=' -f 1`
Val=`echo -n "$Option" | /usr/bin/cut -d '=' -f 2`
if [ "${Val##*[!0-9]*}" ] ; then
case "$Var" in
book) ValidOption="Book=$Val" ;;
nup) ValidOption="nUp=$Val" ;;
*) ValidOption='' ;;
esac
else
ValidOption=`/usr/bin/nawk -F: -v Var="$Var" -v Val=",$Val," 'tolower($1) == Var && $2 ~ Val {print $1"="$3}' $FilterName.MappingOptions`
fi
;;
*) Var=
Val="$Option"
ValidOption=`/usr/bin/nawk -F: -v Val=",$Val," '$2 ~ Val {print $1"="$3}' $FilterName.MappingOptions`
;;
esac
if [ -n "$ValidOption" ]; then
eval $ValidOption
LogTrace "\t'$CmdOption'\t==> '$ValidOption'"
else
LogInfo "\t'$CmdOption'\tIgnored"
fi
done < "$TMPDIR/Options"
fi
}


#
# FixOptions: Initialize options with default values if not set
# change/calculate others options depending on values of other options
#
FixOptions() {
local WidthDPI HeightDPI WidthInches HeightInches WidthPixels HeightPixels WidthPoints HeightPoints

LogTrace "Running 'FixOptions'"
WidthDPI=`echo -n "$Resolution" | /usr/bin/cut -d 'x' -f 1`
HeightDPI=`echo -n "$Resolution" | /usr/bin/cut -d 'x' -f 2`

[ -z "$PaperSizeInches" ] && PaperSizeInches=`/usr/bin/nawk -F: -v Opt=",$PaperSize," '$2 ~ Opt {print $4}' $FilterName.MappingOptions`
WidthInches=`echo -n "$PaperSizeInches" | /usr/bin/cut -d 'x' -f 1`
HeightInches=`echo -n "$PaperSizeInches" | /usr/bin/cut -d 'x' -f 2`

WidthPixels=`echo "$WidthDPI * $WidthInches" | /usr/bin/bc | /usr/bin/cut -d '.' -f 1`
HeightPixels=`echo "$HeightDPI * $HeightInches" | /usr/bin/bc | /usr/bin/cut -d '.' -f 1`
PaperSizePixels="${WidthPixels}x${HeightPixels}"

# PostScript points (each point is 1/72 inch or 0.35mm)
WidthPoints=`echo "72 * $WidthInches" | /usr/bin/bc | /usr/bin/cut -d '.' -f 1`
HeightPoints=`echo "72 * $HeightInches" | /usr/bin/bc | /usr/bin/cut -d '.' -f 1`
PaperSizePoints="${WidthPoints}x${HeightPoints}"

case "$PaperSize" in
env*)
PaperType=envelope
LogInfo "PaperType=$PaperType (Fixed because PaperSize=$PaperSize)" ;;
*postcard*)
PaperType=thick
LogInfo "PaperType=$PaperType (Fixed because PaperSize=$PaperSize)" ;;
esac

# Fix option for Duplex
: ${DuplexManual:=yes}
: ${Duplex:=off}
: ${Book:=off}

# Fix the margin; expresed in Postscript Points
: ${MarginLeft:=24}
: ${MarginRight:=24}
: ${MarginTop:=24}
: ${MarginBottom:=24}

# Fix option for nUp
: ${nUp:=off}
[ "${nUp}" = "1" ] && nUp=off
: ${nUpLayout:=h}
: ${nUpMargin:=off}
if ValueYes nUpMargin ; then nUpMargin="-m`/bin/expr $MarginBottom - 2` -b2" ; else nUpMargin="-m$MarginBottom" ; fi
: ${nUpBorder:=off}
if ValueYes nUpBorder ; then nUpBorder="-d1" ; else nUpBorder="" ; fi

# Fix option for Copies
: ${CopiesManual:=yes}
: ${Copies:=1}

: ${FilterText:=enscript}
: ${MailLog:=false}
[ -z "$ResCPI" ] && ResCPI=`echo "scale=0; $Width / $WidthInches" | /usr/bin/bc`
[ -z "$ResLPI" ] && ResLPI=`echo "scale=0; $Lenght / $HeightInches" | /usr/bin/bc`
}


#
#
#
DuplexNotification() {
eval HOME=~$User
export HOME DISPLAY=:0
LogTrace "Duplex Notification 'kdialog'\n\tHOME=$HOME\n\tDISPLAY=$DISPLAY"
sudo -E /usr/local/kde4/bin/kdialog --msgbox "You printed a file in duplex mode. The 1st part has been sent to the printer $Queue.\n\nWait for all pages to be ejected, then put them back into the printer.\n\nTo print the rest of the job, clic in the button" --title "Duplex Notification"
}


#
# SendToPrinter: Send the file to StdOut (attached to the printer device)
#
SendToPrinter() {
local lnCopies

lnCopies=$Copies
if ValueYes CopiesManual ; then
lnCopies=1
fi
while [ $lnCopies -le $Copies ] ; do
LogTrace "Sendig to printer ($lnCopies)"
/bin/cat "$1"
lnCopies=`/bin/expr $lnCopies + 1`
done
}


#
# PrintJob:
#
PrintJob() {
SendToPrinter "$TMPDIR/1stPart"
if ValueYes Duplex && ValueYes DuplexManual ; then
DuplexNotification
SendToPrinter "$TMPDIR/2ndPart"
fi
}


#
#
#
PreProcessingFile() {
local OptTemp

if ValueYes Book ; then
Book=`/bin/expr $Book \* 4`
LogTrace "Running 'psbook'\n\tpsbook -q -s$Book FileIn FileOut"
/usr/local/bin/psbook -q -s$Book "$TMPDIR/FileIn" "$TMPDIR/FileOut" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"
nUp=2
nUpMargin="-m`/bin/expr $MarginBottom - 27` -b27" # inner magin 27 PostScript points (3/8" 9mm)
nUpLayout=h
Duplex=short
fi
if ValueYes nUp ; then
case "$nUpLayout" in
lrtb|h) OptTemp="" ;; # Horizontal Left to right, top to bottom (default)
rltb|hr) OptTemp="-r -c" ;; # Horizontal Reversed Right to left, top to bottom
tblr|v) OptTemp="-c" ;; # Vertical Top to bottom, left to right
tbrl|vr) OptTemp="-r" ;; # Vertical Reversed Top to bottom, right to left
esac
LogTrace "Running 'psnup'\n\tpsnup $OptTemp $nUpMargin $nUpBorder -$nUp -q FileIn FileOut"
/usr/local/bin/psnup $OptTemp $nUpMargin $nUpBorder -$nUp -q "$TMPDIR/FileIn" "$TMPDIR/FileOut" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"
fi
case "$Duplex" in
no|false|off)
OptTemp="--simplex" ;;
short)
OptTemp="--tumble" ;;
long)
OptTemp="--duplex" ;;
esac
[ "$PaperTray" = "manual" ] && OptTemp="$OptTemp --manualfeed"
LogTrace "Running 'psset'\n\tpsset --quiet --no-fix $OptTemp --output=FileOut FileIn"
/usr/local/bin/psset --quiet --no-fix $OptTemp --output="$TMPDIR/FileOut" "$TMPDIR/FileIn" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"

JobPages=`/usr/local/bin/psselect -p_1 "$TMPDIR/FileIn" 2>&1 > /dev/null | /usr/bin/tr "[]" ":" | /usr/bin/cut -d ':' -f 2`
LogTrace ">>>\tJobPages=$JobPages"

if ValueYes DuplexManual && ValueYes Duplex ; then
if [ `/bin/expr $JobPages % 2` -eq 1 ] ; then
LogTrace "Running 'psselect (adding 1 page for even pages)'\n\tpsselect -q -p1-,_ FileIn FileOut"
/usr/local/bin/psselect -q -p1-,_ "$TMPDIR/FileIn" "$TMPDIR/FileOut"
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"
fi
/usr/local/bin/psselect -q -e -r "$TMPDIR/FileIn" "$TMPDIR/1stPart"
/usr/local/bin/psselect -q -o "$TMPDIR/FileIn" "$TMPDIR/2ndPart"
if [ "$Duplex" = "long" ] ; then
/bin/mv "$TMPDIR/1stPart" "$TMPDIR/FileIn"
/usr/local/bin/pstops -q 'U(1w,1h)' "$TMPDIR/FileIn" "$TMPDIR/1stPart"
fi
/bin/rm "$TMPDIR/FileIn"
else
/bin/mv "$TMPDIR/FileIn" "$TMPDIR/1stPart"
fi
}


#
#
#
PrintPostScript() {
local lcFile

PreProcessingFile
if [ "$GS_DEVICE" != ps ] ; then
GS_FONTPATH=/usr/local/share/ghostscript/fonts:/usr/local/lib/X11/fonts/Type1
GS_LIB=
# -g<width>x<height> page size in pixels | -r<res> pixels/inch resolution
GS_OPTIONS="$GS_OPTIONS -g$PaperSizePixels -r$Resolution -q -dBATCH -dSAFER -dNOPAUSE"
#GS_OPTIONS="$GS_OPTIONS -sPAPERSIZE=$PaperSize -r$Resolution -q -dBATCH -dSAFER -dNOPAUSE"
export GS_DEVICE GS_FONTPATH GS_LIB GS_OPTIONS
LogTrace "Running 'gs'\n\tGS_DEVICE='$GS_DEVICE'\n\tGS_LIB='$GS_LIB'\n\tGS_FONTPATH='$GS_FONTPATH'\n\tGS_OPTIONS='$GS_OPTIONS'"
for lcFile in "1stPart" "2ndPart" ; do
if [ -f "$TMPDIR/$lcFile" ] ; then
LogTrace "\tgs -sOutputFile=FileOut $lcFile"
/usr/local/bin/gs -sOutputFile="$TMPDIR/FileOut" "$TMPDIR/$lcFile" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/$lcFile"
type PostProcessingFile > /dev/null 2>&1 && PostProcessingFile "$lcFile"
fi
done
fi
PrintJob
}


#
#
#
PrintPDF() {
LogTrace "Running 'pdf2ps'\n\tpdf2ps FileIn FileOut"
/usr/local/bin/pdf2ps "$TMPDIR/FileIn" "$TMPDIR/FileOut" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"
PrintPostScript
}


#
#
#
PrintEnscript() {
local WidthPoints HeightPoints

WidthPoints=`echo -n "$PaperSizePoints" | /usr/bin/cut -d 'x' -f 1`
HeightPoints=`echo -n "$PaperSizePoints" | /usr/bin/cut -d 'x' -f 2`
HOME=$TMPDIR
# enscript doesn't use HOME environment variable, uses the value from passwd(5)
# daemon ==> /root
# $HOME/.enscriptrc ==> /root/.enscriptrc
# HOME=/root
# Media definitions for enscript:
# name width height llx lly urx ury
#Media: letter 612 792 38 24 574 768
echo -e "Media:\t$PaperSize\t$WidthPoints\t$HeightPoints\t$MarginLeft\t$MarginTop\t`/bin/expr $WidthPoints - $MarginRight`\t`/bin/expr $HeightPoints - $MarginBottom`" > "$HOME/.enscriptrc"
LogTrace "Running 'enscript'\n\tAdding to \$HOME/.enscriptrc\n\tMedia:\t$PaperSize\t$WidthPoints\t$HeightPoints\t$MarginLeft\t$MarginTop\t`/bin/expr $WidthPoints - $MarginRight`\t`/bin/expr $HeightPoints - $MarginBottom`"
PaperOrientationES="--$PaperOrientation"
ColorModeES="--color=blackwhite"
if [ "$ColorMode" = "color" ] ; then
ColorModeES="--color=emacs"
fi
ENSCRIPT="--no-header --copies=1 --quiet --indent=${Indent}p --lines-per-page=$Lenght --media=$PaperSize $ColorModeES $PaperOrientationES"
export HOME ENSCRIPT
LogTrace "\tENSCRIPT='$ENSCRIPT'"

LogTrace "\tenscript --output=FileOut FileIn"
/usr/local/bin/enscript --output="$TMPDIR/FileOut" "$TMPDIR/FileIn" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"
PrintPostScript
}


#
#
#
PrintA2PS() {
local WidthPoints HeightPoints

WidthPoints=`echo -n "$PaperSizePoints" | /usr/bin/cut -d 'x' -f 1`
HeightPoints=`echo -n "$PaperSizePoints" | /usr/bin/cut -d 'x' -f 2`
# Media definitions for a2ps:
# name width height llx lly urx ury
#Medium: letter 612 792 38 24 574 768
export HOME=$TMPDIR
/bin/mkdir -p "$HOME/.a2ps"
echo -e "Options:\t--quiet --columns=1 --rows=1 --major=rows --borders=off --no-header\nMedium:\t$PaperSize\t$WidthPoints\t$HeightPoints\t$MarginLeft\t$MarginTop\t`/bin/expr $WidthPoints - $MarginRight`\t`/bin/expr $HeightPoints - $MarginBottom`" > "$HOME/.a2ps/a2psrc"
LogTrace "Running 'a2ps'\n\tAdding to \$HOME/.a2ps/a2psrc\n\tOptions:\t--quiet --columns=1 --rows=1 --major=rows --borders=off --no-header\n\tMedium:\t$PaperSize\t$WidthPoints\t$HeightPoints\t$MarginLeft\t$MarginTop\t`/bin/expr $WidthPoints - $MarginRight`\t`/bin/expr $HeightPoints - $MarginBottom`"
LogTrace "\ta2ps --medium=$PaperSize --$PaperOrientation --margin=$Indent --chars-per-line=$Width --lines-per-page=$Lenght --output=FileOut FileIn"
/usr/local/bin/a2ps --medium=$PaperSize --$PaperOrientation --margin=$Indent --chars-per-line=$Width --lines-per-page=$Lenght --output="$TMPDIR/FileOut" "$TMPDIR/FileIn" 2> "$TMPDIR/Error" || ErrorRunning
/bin/mv "$TMPDIR/FileOut" "$TMPDIR/FileIn"
PrintPostScript
}


#
#
#
PrintText() {
case "$FilterText" in
a2ps) PrintA2PS ;;
enscript) PrintEnscript ;;
*)
LogInfo "FilterText is not set properly. Assuming FilterText=enscript"
PrintEnscript ;;
esac
}


###############################################################################
# *** Main Body ***
###############################################################################
Queue=`/usr/bin/basename "$PWD"`
JobPages=0

#
# Process command line arguments
#
while getopts cw:l:i:n:h: Option; do
case $Option in
c) FileType=raw ;;
w) Width=$OPTARG ;;
l) Lenght=$OPTARG ;;
i) Indent=$OPTARG ;;
n) User=$OPTARG ;;
h) Host=$OPTARG ;;
esac
done
eval AccountingFile=\$$OPTIND
unset Option
: ${AccountingFile:=/dev/null}

#
# Load default configuration for the printer/queue (driver name, paper size, method, resolution, etc...)
#
[ -f "$FilterName.conf" ] || ErrorNotConfFile
. $FilterName.conf


#
# Process the control files created by LPD
#
ProcessControlFile

#
# Load user configuration file with options for the printer/queue
# and command line options (-Z)
#
ProcessOptionsFile "`eval echo ~$User`/.config/$FilterName/${Queue}.conf"
ProcessOptionsFile "$TMPDIR/-Z Options"

#
# Fix options
#
FixOptions

/bin/cat - > "$TMPDIR/FileIn"
: ${FileType:=`/usr/bin/file --brief --dereference --mime-type "$TMPDIR/FileIn" | /usr/bin/tr "[:upper:]" "[:lower:]"`}
LogTrace "\n--- ENVIRONMENT VARIABLES ---\n`printenv | /usr/bin/sort`"
LogTrace "\n--- Input-Filter Variables ---\n`set | /usr/bin/grep -e '^[A-Z][a-z]' -e '^nUp' | /usr/bin/sort --ignore-case`\n"

case "$FileType" in
raw)
SendToPrinter "$TMPDIR/FileIn" ;;
application/pdf)
PrintPDF ;;
application/postscript)
PrintPostScript ;;
text/*)
PrintText ;;
*)
ErrorFileType ;;
esac

#
# Printer accounting
#
LogTrace "Accounting to $AccountingFile\n\tPagesPrinted=`/bin/expr $JobPages \* $Copies` Host=$Host User=$User"
/usr/bin/printf "%7.2f\t%s:%s\n" `/bin/expr $JobPages \* $Copies` "$Host" "$User" >> "$AccountingFile"

#
# Clean up and exit
#
CleanUp
exit 0
Martin Alejandro Paredes Sanchez
2014-08-24 23:54:53 UTC
Permalink
In its content of

/var/spool/lpd/lj2100/if-MAPS.MappingOptions

put the following

#
# Option Type : Synonyms : Option Value : HxW Inches
#
PaperSize:,letter,carta,:letter:8.5x11
PaperSize:,legal,:legal:8.5x14
PaperSize:,executive,ejecutivo,:executive:7.25x10.5
PaperSize:,a4,:a4:8.27x11.69
PaperSize:,a5,:a5:5.83x8.27
PaperSize:,a6,:a6:4.13x5.83
PaperSize:,env10,sob10,:env10:4.12x9.5
PaperSize:,envdl,sobdl,:envdl:4.33x8.66
PaperSize:,envc5,sobc5,:envc5:6.4x9
PaperSize:,envb5,sobb5,:envb5:6.9x9.8
PaperSize:,envmonarch,sobmonarch,:envmonarch:3.88x7.5
#
Resolution:,600dpi,600x600,:600x600
Resolution:,1200dpi,1200x1200,:1200x1200
#
PaperOrientation:,landscape,horizontal,:landscape
PaperOrientation:,portrait,vertical,:portrait
#
Duplex:,duplexoff,:off
Duplex:,long,longbind,duplexlong,duplex,:long
Duplex:,short,shortbind,duplexshort,:short
#
Book:,book,:1
Book:,bookoff,:off
#
nUpLayout:,lrtb,h,:h
nUpLayout:,rltb,hr,:hr
nUpLayout:,tblr,v,:v
nUpLayout:,tbrl,vr,:vr
nUpMargin:,margin,:on
nUpMargin:,marginoff,:off
nUpBorder:,border,:on
nUpBorder:,borderoff,:off
Martin Alejandro Paredes Sanchez
2014-08-08 04:54:49 UTC
Permalink
El Sat, 02 Aug 2014 06:39:22 -0700 (PDT)
Post by Beeblebrox
hp2100:lp:rm=192.168.1.9:rp=raw:\
:if=/usr/local/libexec/filters/psif:\
:lf=/var/log/lpd-errs:af=/var/spool/lpd/acct:\
:sd=/var/spool/lpd/hp2100:\
If you are going to use foomatic, I recommend this entry in
your /etc/printcap

hp2100|lp|HP LaserJet 2100TN (foomatic):\
:tty.device=:remote.host=192.168.1.9:remote.queue=raw:\
:filt.input=/usr/local/bin/foomatic-rip:\
:spool.log=/var/spool/lpd/hp2100/filter-errors:\
:acct.file=/location/of/file/HP_LaserJet_2100.ppd:\
:spool.dir=/var/spool/lpd/hp2100:\
:max.blocks=0:banner.disable:
Polytropon
2014-07-18 12:06:55 UTC
Permalink
Post by Beeblebrox
Hi.
Cups has been borked for some time, so I must use lpd. Several problems when
1 HP2100tn:rm=192.168.1.9:rp=RAW1:\
2 :sd=/var/spool/lpd/hp2100:lf=/var/log/lpd-errs:\
3 :if=/usr/local/libexec/lf2crlf:\
* Line 1 fails completely with "lpr: lp: unknown printer" when using any
WORKS: lp:rm=192.168.1.9:rp=RAW1:\
This sounds normal. If no printer is given, "lp" is the name
that will be addressed. It is the _default_ printer name that
the lp* tools refer to. If your printer is named differently,
you need to specify -P<name> according to the printcap entry.
You can also define $PRINTER (for example in /etc/csh.cshrc
globally) with the name of the printer.

For example, I have this setting (among others):

Laserjet|ljet4d;r=600x600;q=high;c=full;p=a4;m=auto:\
:rm=192.168.100.100:\
:rp=raw:\
:lp=:\
:if=/opt/libexec/ps2pcl-dup.sh:\
:sd=/var/spool/lpd/Laserjet:\
:lf=/var/spool/lpd/Laserjet/log:\
:af=/var/spool/lpd/Laserjet/acct:\
:mx#0:\
:sh:

It's my default printer, so I set $PRINTER to "Laserjet", and
when I invoke lpr, lpq or lprm, this printer's queue will be
used. For my nondefault printers, I have to use

# lpq -PLaserjet-nodup

for example, but I hardly do this. :-)

In your case, $PRINTER would have to be set to "HP2100tn", or
you use -PHP2100tn (at least for testing).
Post by Beeblebrox
* I need to specify below options. Placing in /etc/printcap (line 1) as
lp;r=300x300;q=draft;c=gray;p=a4;m=auto:\
:rm=192.168.1.9:rp=RAW1:\
results in the same "unknown printer" error. I need to either find the
correct syntax for printcap [...]
See "man printcap" for this.
Post by Beeblebrox
[...] or I could modify /usr/local/libexec/lf2crlf,
#!/bin/sh
CR=$'\r'
/usr/bin/sed -e "s/$/${CR}/g"
## will A4 size info here work?
#page_width=
#page_height=
#border=
Printer: HP LaserJat 2100, PS-level-2
A Postscript printer? Excellent, this should work without any
problems. But I don't see how modifying the printer filter
should help...

Anyway, consult

http://www.wonkity.com/~wblock/docs/html/lpdprinting.html

for more helpful advice. :-)
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Warren Block
2014-07-18 13:20:44 UTC
Permalink
Post by Polytropon
A Postscript printer? Excellent, this should work without any
problems. But I don't see how modifying the printer filter
should help...
Anyway, consult
http://www.wonkity.com/~wblock/docs/html/lpdprinting.html
for more helpful advice. :-)
Thanks! Actually, filters can be used to modify the PostScript as it is
printed, setting a paper size or enabling duplex printing. Here is an
example: https://forums.freebsd.org/viewtopic.php?&t=40651
Loading...