# FreeBSD and JetDirect



## bnorton916 (Oct 14, 2014)

I have a HP LaserJet 9000N hooked up to the network and configured.

`nc 192.168.1.1 9100 < myfile.txt`
works just fine from FreeBSD shell.

Now I would prefer to setup a FreeBSD print server.

I have read the howto's, but to be honest with apsfilter, magicfilter, cups, lpd, gutenbergprint, hplip, I believe I am getting things confused.

I have been able print using lpd() and /etc/printcap from different machines pointing back to my FreeBSD print server. But I haven't been able to print from different trays.

I prefer not to use CUPS, as I have just PostScript printers on the network (my understanding is that cups excels in the non-PostScript space).

So, what is the recommend method or if there are many recommended methods: what is your recommended method?

Thanks,

Bill


----------



## wblock@ (Oct 14, 2014)

You already have a FreeBSD print server.  If you want to use a different tray, that needs to be part of the PostScript file.  There are threads here showing filters that add the information, but I apparently did not bookmark the one that showed using a filter to enable duplexing.  Tray selection is very similar.


----------



## bnorton916 (Oct 14, 2014)

Excuse my ignorance here but that would mean I would need a filter to change the tray.

So my printcap file would look something like this:


```
billtesttray2:\
        :lp=:rm=192.168.1.119:rp=text:lf=/var/log/lpd-errs:\
        :of=/path/trayfilter:\
        :sd=/var/spool/lpd/billtesttray2:mx#0:sh:
```

Or am I completely off?

Thanks,

Bill


----------



## wblock@ (Oct 14, 2014)

That's the right idea: have different queues for different actions.


----------



## bnorton916 (Oct 15, 2014)

I installed apsfilter and test printing works just fine. 

My problem is that is always prints from the same tray.


```
lpr -Pbillhog -C tray0 ~norton/testpage.txt
lpr -Pbillhog -C tray1 ~norton/testpage.txt
lpr -Pbillhog -C tray2 ~norton/testpage.txt
```

All print from tray 3. 

I am not sure how to write a filter for this as I can't even get it to work from the command line?

What am I missing?

Thanks,

Bill


----------



## bnorton916 (Oct 15, 2014)

Not sure if I should ask here or start a new thread.

I read(post from 2000) that if you use

```
rp=raw:
```

then lpd() completely bypasses any filter.
I was getting stair-stepping so I changed to 
	
	



```
rp=ascii:
```
 and text prints fine now but I am worried about printing non-ASCII items.

Same post said that apsfilter doesn't work well with remote printers. Is this still true?

Ideas?

Bill


----------



## wblock@ (Oct 16, 2014)

bnorton916 said:


> Not sure if I should ask here or start a new thread.
> 
> I read(post from 2000) that if you use
> 
> ...



No, that's not accurate.  The FreeBSD lpd() command does not do that.  However, there is a queue named raw built into the JetDirect.  Print data sent to that queue is printed without any changes.



> I was getting stair-stepping so I changed to
> 
> 
> 
> ...



The Handbook printing chapter shows how to use filters for that.



> Same post said that apsfilter doesn't work well with remote printers. Is this still true?



No idea, I have never used print/apsfilter.


----------



## wblock@ (Oct 16, 2014)

bnorton916 said:


> I installed apsfilter and test printing works just fine.
> 
> My problem is that is always prints from the same tray.



print/apsfilter is a big do-it-all filter.  I do not use it.  A "tray" filter would have to modify the incoming PostScript file directly.


----------



## wblock@ (Oct 16, 2014)

Thread 40651 shows how to create a filter that enables duplexing, or double-sided printing.


----------



## bnorton916 (Oct 28, 2014)

First, thanks to wblock@ for your help.

Second, I uninstalled print/apsfilter as I could never get it to work.

Third, I never could get printing working to other trays even when I directly edited the PostScript file. I am still looking into this.

Fourth, I used wblock@'s psif script but modified it for PDF files and TIFF files. Some changes had to be made (read kept stripping out the NULLs in the TIFF file).
There may be some unforeseen problem with the script, so use with discretion.
I thought others might find it useful.


```
#!/usr/local/bin/bash

IFS="" read -N 2 -r -d '' first_line
first_two_chars=`expr "$first_line" : '\(..\)'`

case "$first_two_chars" in
%!|\033%%)
    # %! or ESC% : PostScript job, print it.
    echo -n "$first_line" && cat && printf "\004" && exit 0
    exit 2
    ;;

MM)
    # tif file
    # little nervous a doc could start with MM
    ( echo -n "$first_line"; cat ) \
    | /usr/local/bin/fax2ps -W8.5 -H10.5 && printf "\004" && exit 0
    exit 2
    ;;

%P)
    # %P not sure if other files other than PDF start with %P
    ( echo -n "$first_line"; cat ) \
    | /usr/local/bin/pdf2ps - - && printf "\004" && exit 0
    exit 2
    ;;

*)
    # otherwise, format with enscript
    ( echo -n "$first_line"; cat ) \
      | /usr/local/bin/enscript -o - && printf "\004" && exit 0
    exit 2
    ;;
esac
```


----------



## wblock@ (Oct 28, 2014)

file(1) is a better way to detect file type.  The original psif got away without it because PostScript files follow a well-known format, and it kept the demonstration relatively simple.


----------



## bnorton916 (Oct 28, 2014)

wblock@ said:


> file(1) is a better way to detect file type. The original psif got away without it because PostScript files follow a well-known format, and it kept the demonstration relatively simple.



I was wondering this and starting writing a script to use file instead of the above. Having a couple of problems but I am no sh  guru.

Bill


----------



## Oko (Oct 28, 2014)

bnorton916 said:


> I have a HP LaserJet 9000N hooked up to the network and configured.
> 
> `nc 192.168.1.1 9100 < myfile.txt`
> works just fine from FreeBSD shell.
> ...



Unfortunately you are beating a dead horse. I used until 1.5 year ago this simple printcap file on my OpenBSD machine


```
lp|HP|HP-Photosmart_5200:\
        :lp=/dev/ulpt0:\
        :af=/etc/foomatic/HP-PhotoSmart_C5200.ppd:\
        :if=/usr/local/bin/foomatic-rip:\
        :sh:sd=/var/spool/output:\
        :lf=/var/log/lpd-errs:
```

Then the idiots from the Linux foundation got the idea that foomatic-rip should no longer support LPD or any other spooling except CUPS for that matter because as we know everyone has to use CUPS. Long story short my printer still works but I have to call foomatic-rip manually to convert a file from PostScript into PCL5 and then to stream it to lpd. Obviously foomatic-rip is just a Perl wrapper which calls the driver for me. Somebody suggested you Apsfilter. Please don't use that ancient piece of software which is just a cheap wrap around foomatic-rip. Just spend $50 for a used printer which supports PostScript and remove any input filters from your printcap file. Another idea is that you just a write small input filter yourself (I have done that for LaserJet 4) as it likely uses GhostScript drivers and it is essentially two liner. Just suppress the printer wake up and a second line is to call the GhostScript command with a bunch of options.


----------



## bnorton916 (Oct 29, 2014)

I have dumped print/apsfilter, I simply couldn't get it to work. Too bad about foomatic-rip, what was the reason for doing this?

I have a PostScript printer, but I need to be able to print PDF, DVI, TIFF files from the command line.

It currently works but I believe it could be a little cleaner than what I did above.

Bill


----------



## Oko (Oct 29, 2014)

bnorton916 said:


> I have a postscript printer, but I need to be able to print pdf, dvi, tiff files from the command line.


So what prevents you from doing it. Conversion filter is just a Perl script which detect the type of the file and call conversion program. So when you send for example PDF file to printer foomatic-rip detect it is PDF file. It calls pdf2ps utility and once the file is translated into PostScript calls the driver which converts PostScript to the language understandable by printer like PCL6 for example. Check out a2ps application. It essentially converts everything to PostScript and sends to default printer. So if you have a PostScript printer: `a2ps -1 myfile.pdf` will print the file on your printer.


----------



## bnorton916 (Oct 29, 2014)

With regards to PDF's, my current filter does this. But I think it could be a[]lot better.

I had never heard of a2ps until your post. It doesn't seem to work with TIFF files though. It prints out garbage saying it can't find tiff.ssh. 

It prints out DVI and PDF files just fine though.

Bill


----------



## wblock@ (Oct 29, 2014)

graphics/ImageMagick or graphics/GraphicsMagick can convert between almost any formats, including PostScript.


----------



## bnorton916 (Oct 29, 2014)

wblock@ said:


> graphics/ImageMagick or graphics/GraphicsMagick can convert between almost any formats, including PostScript.



With regards to TIFF files, fax2ps works just fine. print/a2ps works just fine except for TIFF files.

So I figure out what's wrong with a2ps or write a filter to call a2ps for everything except TIFF files. Or maybe just improve my current script.

I need users to be able to do
`lpr foo.dvi`
`lpr foo.tiff`
`lpr foo.pdf`
without intervention from me, preferably using only one queue.

Bill


----------



## Oko (Nov 2, 2014)

I know that many people were very frustrated when upstream broke foomatic-rip for LPD users. Thanks to Antoine Jacoutot of OpenBSD many of us will be CUPS free for years to come. I am leaving internet trace for people who would be looking for the info but Antoine documentation which comes with OpenBSD

/usr/local/share/doc/pkg-readmes/cups-filters*

is golden standard.

In the nut shell what I did:

0. Install *foomatic-rip*, drivers (in my case *hpijs*), *a2ps*, *ImageMagick*

1. Edit /etc/printcap as

```
lp|HP|HP-PhotoSmart_C5200:\
  :lp=/dev/ulpt0:\
  :if=/etc/foomatic-rip/script.sh:\
  :sh:sd=/var/spool/output:\
  :lf=/var/log/lpd-errs:
```

2. Create /etc/foomatic-rip.script.sh and make it executable


```
#!/bin/sh

/usr/local/bin/a2ps -BRq --columns=1 -o - | \
  /usr/local/bin/foomatic-rip -P HP-PhotoSmart_C5200 --ppd \
  /etc/foomatic-rip/direct/hp-photosmart_c5200_series-hpijs.ppd
```

3. Add *hp-photosmart_c5200_series-hpijs.ppd* to /etc/foomatic-rip/direct. You can either find it in the database or use *foomatic-ppdfile* to create it.

4. Adjust permission on *ulpt0* and *ugen *devices.

5. Start *lpd* daemon and be happy camper.


----------

