# LPD/LPR and apsfilter: ghostscript9 *.ps files not printing



## benat (May 28, 2014)

Hello,

It is my first post and I'm not sure this is the right place to post my question, so please be indulgent. Also, I hope I'm following the forum's rules and guidelines properly.

I have FreeBS*D* 9.2-RELEASE installed, my ports tree is up to date, so are installed ports. Everything was installed from ports, not (PKGNG) packages. I have installed print/apsfilter and I'm trying to get my postscript network printer (Brother HL-5250DN) to work. I have read many documents, including the Handbook and Warren Block's article. 

So far I can:
 print a file from a word processor (Abiword)
 print a .txt (ASCII) file from the command line with `$ lpr loreipsum.txt`
 print a .ps (PostScript) file from the command line with `$ lpr loreipsum.abw.ps` *if the file was created by Abiword* (Edit ->Save As [postscript *.ps])
I'm having trouble printing .pdf files because they go through pdf2ps which is part of print/ghostscript9. For example, the following *doesn't work*:
 `$ lpr loreipsum.abw.pdf` , the loreipsum.abw.pdf file being initially created by Abiword (Edit ->Save As [portable document format *.pdf])
 `$ pdf2ps loreipsum.abw.pdf loreipsum.gs9.ps`, then `$ lpr loreipsum.gs9.ps`
Sometimes the lpr command fails silently (nothing happens) and sometimes I get a blank page.

Opening files loreipsum.abw.ps and loreipsum.gs9.ps with emacs I can see they differ a lot, the former being generated by graphics/cairo (which is used by Abiword) and the later by ghostscript9 as said before. But the file command gives the same result for both:


```
$ file loreipsum.gs9.ps 
loreipsum.gs9.ps: PostScript document text conforming DSC level 3.0, Level 2
$ file loreipsum.abw.ps 
loreipsum.abw.ps: PostScript document text conforming DSC level 3.0, Level 2
```
At this point I'm stuck because calling ghostscript9 is supposed to be the right thing to do by the smart filter apsfilter, so the whole process should be straightforward. Or am I missing something obvious here? I copy the relevant files /etc/printcap and apsfilterrc below.

As a side note, I can't get LPD and/or apsfilter to make use of the .PPD file which comes with my printer, so that I can benefit from all the functionality it provides.

Any help will be very appreciated. Many thanks in advance.


```
# APS1_BEGIN:hl5250dn
lp|rlp|hl5250dn|Brother HL-5250DN:\
    :lp=:sd=/var/spool/lpd/hl5250dn:\
    :rm=hl5250dn:\
    :rp=hl5250dn:\
    :lf=/var/log/lpd-hl5250dn.log:\
    :af=/var/spool/lpd/hl5250dn/acct:\
    :if=/usr/local/etc/apsfilter/basedir/bin/apsfilter:\
    :sh:mx#0:
# APS1_END - don't delete this
```


```
PRINTER='PS'
PAPERSIZE='a4'
METHOD='auto'
QUALITY='medium'
COLOR='full'
RESOLUTION='600x600'
INTERFACE='network'
```

Please note that hl5250dn is the name of the spool and also the DNS name of my printer (hl5250dn.domain.lan). I can ping and dig it without any problem. Obviously using its IP address in /etc/printcap (i.e. rm=9100@192.168.xxx.yyy) doesn't solve my issue.


----------



## wblock@ (May 28, 2014)

*Re: LPD/LPR and apsfilter: ghostscript9 *.ps files not print*

Convert the PDF and send it directly to the printer, bypassing apsfilter[p/file].  If it still does not print, convert it but limit it to PostScript level 1 and see if that can be printed:
`pdf2ps -dLanguageLevel=1 loreipsum.abw.ps`

If that Brother printer supports it, port 9100 printing is sometimes more reliable.


----------



## benat (May 28, 2014)

*Re: LPD/LPR and apsfilter: ghostscript9 *.ps files not print*

Hello,

Many thanks to @wblock@ for replying. Unfortunately converting the file and sending it directly to the printer doesn't work:


```
$ nc 192.168.1.20 9100 < loreipsum.abw.ps                 # works (.ps generated by abiword/cairo)
$ nc 192.168.1.20 9100 < loreipsum.gs9.ps                 # doesn't work (.ps created by pdf2ps), "prints" a blank page
$ pdf2ps loreipsum.abw.pdf - | nc 192.168.1.20 9100       # doesn't work, "prints" a blank page
$ pdf2ps -dLanguageLevel=1 loreipsum.abw.pdf - | nc 192.168.1.20 9100    # doesn't work, "prints" a blank page
```
Looks like this is a print/ghostscript9 issue to me, but googling doesn't show anything helpful. I had pdf2ps and the same printer working without any problem for years before with a FreeBSD 8.0-RELEASE. I will continue investigating why those two postscript files are so different in spite of file saying they are the same.

Thank you very much again.


----------



## wblock@ (May 28, 2014)

*Re: LPD/LPR and apsfilter: ghostscript9 *.ps files not print*

file(1) just checks for certain characteristics.  The problem may be the clone PostScript ("BRScript") in the printer.  The printer vendors use these clone versions to avoid paying license fees to Adobe, but I've found small incompatibilities in HP and Oki versions in the past.

Maybe feed the converted PostScript output to ps2ps to try to remove any oddness before printing?

One other thought: if the PDF is one of those that is not actually text but a giant bitmap, the printer might be running out of memory.  HP lasers default to merely aborting problem pages, but can be set to print a PostScript error page.  Maybe something similar is available on the Brother.


----------



## benat (May 28, 2014)

*Re: LPD/LPR and apsfilter: ghostscript9 *.ps files not print*

Thanks @wblock@. 

The loreipsum.abw.pdf is a PDF text file, and so is the PostScript file loreipsum.abw.ps created by Abiword. The PostScript files generated by print/ghostscript9 are much bigger and look more like "giant bitmaps", but they still have some legible lines inside.

I have tried the ps2ps command (by the way thanks for pointing that to me because I didn't know): 

```
$ ps2ps loreipsum.gs9.ps - | nc 192.168.1.20 9100     # doesn't work, blank page
$ ps2ps loreipsum.abw.ps - | nc 192.168.1.20 9100     # doesn't work, blank page
```
I don't think the printer is running out of memory because I'm doing all my tests with a one page document (5 paragraphs of the "lore ipsum" dummy text). I used to print much bigger reports with that same printer.

I have just noticed that the `-dLanguageLevel=*` option of pdf2ps doesn't work: I get exactly the same (level 2) PostScript file regardless of the level used. I will google about this. Thank you much.


----------



## benat (May 28, 2014)

*Re: LPD/LPR and apsfilter: ghostscript9 *.ps files not print*

I'm going to reply to my own post in case this can help someone in the future.

I kind of solved my problem by installing graphics/poppler-utils which comes with pdftops and a handful of PDF related utilities. When trying to print a PDF file, apsfilter looks first for acroread (print/acroreadwrapper) conversion tools, then pdftops, and falls back to pdf2ps as a last resort if nothing better was found:

```
$ less /usr/local/share/apsfilter/bin/apsfilter    # then look for function print_pdf()
```
The pdf2ps utility is a lightweight wrapper around gs which, for some odd reason, seems to be causing problems with several printers. This thread put me on the way. With pdftops installed everything seems to be working again. I will do more testing tomorrow, and I still want apsfilter to use my PPD file   

Thanks a lot @wblock@ for your time and help.

UPDATE 30 May 2014: Just for the record, I have found that my problem was discussed in these two bug reports: Brother printer fails to print anything but a blank page and CUPS: Prints one blank sheet regardless of document size (Brother HL-5240).


----------

