View Full Version : Printer setup question
JMJ_coder
06-14-2008, 09:26 PM
Hello,
I setup my lpd and printcap for my Brother laser printer (PostScript enabled) on my NetBSD system. The problem I am having is that the filter I wrote for it creates an error when handling shell script files. I think the error comes when the filter tries to process the files commands instead of printing them, but I am unsure of how to fix it.
Here is my /etc/printcap:
lp|local printer|Brother HL-5240
:lp=/dev/ulpt0:sd=/var/spool/lpd/lp:lf=/var/log/lpd-errors:\
:sh:mx#0:if=/usr/pkg/bin/t2ps-filter:
I took the filter straight out of "FreeBSD: The Complete Reference". Here is the t2ps-filter:
#!/bin/sh
# Check to see if input is PostScript. If not, pass through enscript.
read firstline
firstline=`expr "$firstline" : '\(..\)'`
if [ "$firstchars" = "%!" ]
then
# PostScript file; pass through $firstline and rest of file
echo "$firstline" && cat && printf "\004"
exit 0
else
# Not PostScript file; use enscript to process
(echo "$firstline"; cat) | /usr/pkg/bin/enscript -p- \
&& printf "\004"
exit 0
fi
J65nko
06-15-2008, 06:49 AM
You don't define the variable ${firstchars}.read firstline
firstline=`expr "$firstline" : '\(..\)'`
if [ "$firstchars" = "%!" ]IMHO that should beread firstline
firstchars=`expr "$firstline" : '\(..\)'`
if [ "$firstchars" = "%!" ]
JMJ_coder
06-16-2008, 12:55 PM
Hello,
You don't define the variable ${firstchars}.read firstline
firstline=`expr "$firstline" : '\(..\)'`
if [ "$firstchars" = "%!" ]IMHO that should beread firstline
firstchars=`expr "$firstline" : '\(..\)'`
if [ "$firstchars" = "%!" ]
Ooops. I mistyped - it is firstchars=`expr "$firstline" : '\(..\)'` in the actual file.
robbak
06-16-2008, 02:23 PM
What happens when you pipe a doc through that shell script -say cat textfile | /usr/pkg/bin/t2ps-filter
Then try cat-ting a postscript file through it - Do you get the desired output?
JMJ_coder
06-16-2008, 11:53 PM
Hello,
What happens when you pipe a doc through that shell script -say cat textfile | /usr/pkg/bin/t2ps-filter
Then try cat-ting a postscript file through it - Do you get the desired output?
I can print regular text files fine. The problem is when I try to print a shell script text file (i.e., try to print the t2ps-filter).
robbak
06-17-2008, 01:55 AM
Ok then, what happens when you cat a shell script through t2ps-filter?cat /usr/pkg/bin/t2ps-filter | /usr/pkg/bin/t2ps-filter
It worked for me (at least, the logic did: I don't have /usr/pkg/bin/enscript on FreeBSD). Perhaps the printer is trying to interpret #! as..., no wait, it should be getting postscript. No, I have nothing.
OH, and please don't just tell us that it gives you 'an error'. WHAT ERROR??!??
JMJ_coder
06-17-2008, 02:04 AM
Hello,
I don't know why, but it is working now! It didn't work for me all yesterday, and now it does. :confused:
I have one more question on the subject of printing. I am using enscript, which allows for different fonts with the --font=name switch. Which font should I use to get all the characters to print correctly? The default is messing up at least one. In particular, I need "`" to print differently than "'". The default font enscript uses prints both characters identically.
I tried a couple others - Courier12; Courier@12, which is straight from the man pages didn't even print for me - and got nowhere.
JMJ_coder
06-17-2008, 02:08 AM
Hello,
OH, and please don't just tell us that it gives you 'an error'. WHAT ERROR??!??
The error it was giving was printed on the page from the printer - ERROR NAME;
undefined
COMMAND;
e
OPERAND STACK;
robbak
06-17-2008, 02:40 AM
Without looking at the data it was sending the printer (which you can get with that cat trick), I couldn't say. It looks like it was barfing over something in enscripts dialect of postscript, to my mind. Your font fiddling may have inadvertently fixed it.
I'm afraid that I don't know enough of the internals of postscript to advise you about fonts. For this basic usage, I'd suspect you are limited to fonts that are embedded in the printer. You may find what fonts are available in the printer's manual.
JMJ_coder
06-17-2008, 02:57 AM
Hello,
Without looking at the data it was sending the printer (which you can get with that cat trick), I couldn't say. It looks like it was barfing over something in enscripts dialect of postscript, to my mind. Your font fiddling may have inadvertently fixed it. I didn't start fiddling with fonts until after it started working again. I don't know - it's just one of those things that don't work one moment but then start working again.
Actually, when I started to tweak the fonts, it gave me garbage again - when it even printed. I had to quickly fix the syntax of the script. And actually, I found that if I just use the enscript command instead of trying to incorporate it in the filter it works ten times better. I think I will just alias lpr to enscript.
I'm afraid that I don't know enough of the internals of postscript to advise you about fonts. For this basic usage, I'd suspect you are limited to fonts that are embedded in the printer. You may find what fonts are available in the printer's manual.I tried most of the fonts provided by enscript (it uses afm fonts). The only monospaced font appears to be Courier, which doesn't differentiate ` from '. Some of the other fonts do, but they are proportional.
I'll have see if I can scrounge up a better font, because on this setup I am printing a lot of source code - including shell scripts with 's and`s galore. I need a monospaced font that properly prints all of my common characters.
Thanks for the help.
JMJ_coder
11-04-2008, 07:35 PM
I'm revisiting this question as I setup my laptop to use my printer. I'm half tempted to just install cups and give that a go. But, if I can, I think the base lpr daemon should work fine. I'm either going to print plain text, or I can get non-plain text into a .ps file that can be printed.
I have two questions:
Does the print output of programs such as Firefox (or any browser) and OpenOffice play nice with the lpr daemon? Does it need to be configured with any special options for that?
I had problems with fonts before. Basically the lpr daemon - whatever font it used didn't print every character I needed. Noteably a backtick - ` - was printed as a single quote - ' -. You can imagine the difficulties when I printed out things such as shell scripts. The lpr man page says:
-[1234]font
Specifies a font to be mounted on font position i. The daemon
will construct a .railmag file referencing the font pathname.
...but I find this confusing. What does the [1234] signify - do they all need to be present or do they represent various options; and what is the .railmag file?
I'm revisiting this question as I setup my laptop to use my printer. I'm half tempted to just install cups and give that a go.
OK. Please, do not panic. CUPS is for enterprise printing. You do not have 300 printers and 35 different user groups. You do not want that cr*** on your pristine NetBSD machine.
I will give you three suggestions:
1. Note that your Brother HL-5240 (good choice by the way) also speaks Printer Command Language 6. Yes, I do know that theoretically it should be easier just to use as Post Script printer but sometimes the theory and practice are not the same.
2. Also look at Apsfilter. Apsfilter is the simple script which will allow you to install printer. Actually it will just generate proper printcap file for you. It can be used on Post Script Printers as well as the one using drivers from Ghostscript, Gutenprint, and HPIJS.
3. Finally, you can use the same PPD file you are using in CUPS without installing CUPS. Look at the foomatic-filter.
To answer your second question is more tricky. Whether you can use
LPR directly from Firefox or OpenOffice depends on the guy who ported it
to NetBSD. If he kept vanilla configuration than I assume that these applications will expect CUPS. However they will be more than happy to print to post script file which you can pipe to the printer.
You can obviously configure OpenOffice and Firefox to do this automatically.
The advantage of CUPS is that it speaks internet printing protocol IPP unlike LPR which speaks only lpr protocol.
The IPP allows printer to report back to the computer its status. In reality only very expensive printers speak full IPP. PPD files
among other things describe how to fake IPP conversation with the particular printer.
Cheers,
OKO
JMJ_coder
11-06-2008, 12:04 AM
Thanks Oko. I did end up installing CUPS, for the simple fact that right now it is the lowest common denominator. I know it will work, and I know how to configure it - and I need to print. As I learn the lpd, which I intend to do, I can then revisit whether CUPS has a place in my userland. Probably over the Christmas break I will re-do my installation, and a lot of these questions will then be re-evaluated.
vBulletin® v3.7.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.