Solved Printing: lpd margin problem with ps file

I have a ps file I created from pdf using pdftk tools. The ps file fits perfectly on the a4 page just like I want.

When printing to lpd however, the page gets shifted up by appx 1.2 cm, such that the top section gets shaved and the page bottom has an unnecessarily large margin. Ideas I came up with when trying to solve this problem:
  • I wonder if the system is trying to force the use of letter-size paper rather than a4?
  • I don't think there's any way to adjust margin in printcap/psif (printer is PSII capable, psif sends it directly with cat)? Paper size is not specified in psif - I could try that maybe?
  • I cant use enscript or any other complex filter because they all pipe through ghostscript, which is very clearly broken (at least for me).
EDIT: I think I should either find a way to incorporate the use of libpaper in my psif, or use pl and pw in /etc/printcap.
 
Can you firstly confirm that you are using LPD not CUPS? Please post your /etc/printcap. What do you use to convert PDF file to PostScript? PostScript is the only thing that can be sent to printer which understands it or the driver (you mentioned GhostScript collection of drivers which is NOT broken) If your answer is I don't know check the input filter line in /etc/printcap file. Typically input filter uses print/a2ps or graphics/ImageMagick to convert files to PostScript. Please post the options used to compile those two programs. There is a line for both of these programs which clearly shows if they are compiled with option A4 or Letter. Recently I noticed (for me personally annoying trend since I live in U.S.:rolleyes:) that most programs do default to normal international :) A4 standard.

Try to display paper using built in PostScript interpreter before printing (I mean it is built in into GhostScript).

[ the [port] tag requires category/portname syntax -- Mod. ]
 
GhostScript collection of drivers which is NOT broken
When you run pdf2ps on a pdf fetched from Adobe's site and the document fails to convert, I'd call that broken. Any print job that gets piped through gs results in gibberish, while raw (cat) printing over lpd does just fine - I'd also call that broken. The port might build and install, but does not work. See https://lists.freebsd.org/pipermail/freebsd-ports/2014-October/095975.html

What do you use to convert PDF file to PostScript?
As stated, pdftk. The resulting ps file has correct paper size because I used pdftops -paper A4.

Typically input filter uses a2ps or ImageMagic to convert files to PostScript
The file is already PostScript format so there's no further need for any GhostScript monkey-business nor ps2ps. As stated, psif sends it directly with cat. See Handbook's 10.5.3.4.Smart Filters for psif.
 
A PostScript file can draw the correct image without specifying the paper size. Can you share the PostScript file, or a generic version that has the same problem? Does a PDF created with ps2pdf(1) show correctly in a PDF viewer? Does it print correctly?
 
I decided to try the problem using a Linux distro, so I set up Debian in VirtualBox and configured the network printer through CUPS.

I tried several different PPD files but got the same result with each. I had surmised it was a Letter vs A4 problem (narrower but taller than expected) given that,
  • The left/right margins of the document do not fit to the page and the first letter on the left margin is shaved off.
  • Page gets shifted up by about 1.5 cm, maybe even more.
However, your observation that the page should be auto-adjusted for printer paper size makes sense; yet it seems that's actually not happening for some reason.

One PPD that did give a different result than the rest, was the "CUPS + Gutenprint v5.2.10" driver. It resulted in decent left/right margins, no expanded bottom margin, but the top is still shaved off. Looking closely, it seems this PPD squeezed the page horizontally and maybe expanded vertically, but downwards only. The print quality was also much sharper, yet at the same time the printed characters are noticeably larger, thus making it more readable.

wblock@: I can't say I understand the wisdom behind your ps2pdf suggestion because
  1. That's GhostScript which will probably fail
  2. PDF viewer applications are able to display PostScript files, and yes, these files are displayed correctly.
  3. PDF files cannot print correctly since filters use GhostScript (pdf2ps) and that's broken (prints gibberish). Therefore I am reduced to manually pre-process the file to PostScript format.
  4. As other example, I have an Abiword document, which I save as PostScript when I want to print. I have the same upper-margin problem when printing that file.
So I think that it's not a wrong file format issue, but something else. In any case, link to sample PostScript file
 
Have you try normalizing PostScript file which was produced by pdftk? Just do ps2ps (it is a part of GhostScript) and try again to print a new PostScript file.
 
However, your observation that the page should be auto-adjusted for printer paper size makes sense; yet it seems that's actually not happening for some reason.

I did not mean to imply that printers will auto-adjust the paper size. A PostScript program can draw an A4-sized image without explicitly setting the paper size. That program will still run and print on letter paper, but the image will be cut off. A correct PostScript program will use setpagedevice to set the paper size. There are other options, like automatically calculating the paper size from the bounding box. That might be calculated when converting to a PDF.

Printing from graphics/xpdf directly to the printer does not use a filter, and sends PostScript, not PDF code. I always set up a raw print queue for a PostScript printer, so PostScript files can be sent straight to it.
 
This works:
Code:
% ps2ps -sPAPERSIZE=a4 sample.ps fixed.ps
% ps2pdf -sPAPERSIZE=a4 fixed.ps

The file produced is fixed.pdf.
 
Thanks for your input, but as I stated GhostScript does not work at all. I re-built and installed the port with lang/perl5.18dependency, but no difference. This is true for almost all pdf or ps files I have tried (not just a few handful).
$ ps2ps -sPAPERSIZE=a4 in.ps final.ps
Code:
Error: /undefinedresult in --currentpoint--
Operand stack:
  false  false  false  false  false  false  false  false  false  false  false  false  false  false  false  (CH)  --nostringval--
Execution stack:
  %interp_exit  .runexec2  --nostringval--  --nostringval--  --nostringval--  2  %stopped_push  --nostringval--  --nostringval--  --nostringval--  false  1  %stopped_push  1910  1  3  %oparray_pop  1909  1  3  %oparray_pop  1893  1  3  %oparray_pop  1787  1  3  %oparray_pop  --nostringval--  %errorexec_pop  .runexec2  --nostringval--  --nostringval--  --nostringval--  2  %stopped_push  --nostringval--  --nostringval--
Dictionary stack:
  --dict:1170/1684(ro)(G)--  --dict:0/20(G)--  --dict:96/200(L)--  --dict:70/75(L)--  --dict:19/25(L)--  --dict:10/15(L)--
Current allocation mode is local
Current file position is 3492337
GPL Ghostscript 9.06: Unrecoverable error, exit code 1
I'll just have to figure out some other way to work around this (in Linux or somethig).
 
Back
Top