Bug 64207 - PDF files with nonstandard paper size (like 515x743pt) won't print on a real PostScript printer
Summary: PDF files with nonstandard paper size (like 515x743pt) won't print on a real ...
Status: CONFIRMED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-13 17:09 UTC by Alexander Patrakov
Modified: 2021-03-09 23:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
pdf file with non standard paper size (here the standard is A4) (883.27 KB, application/pdf)
2005-05-18 16:32 UTC, Sebastian Reitenbach
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Patrakov 2003-09-13 17:09:29 UTC
Version:            (using KDE KDE 3.1.3)
Installed from:    Compiled From Sources
Compiler:          gcc 3.2.1 
OS:          Linux

(I report this bug on behalf of my friend who has a real PS printer. I have a non-PS printer myself.)

Currently, kghostview uses gs to convert PDF files to PostScript before printing. If a PDF file has a specific paper size set for one of its pages with a /MediaBox key, then gs will interpret that and insert a corresponding "setpagedevice" into the output PS file.

The problem is that some scanning programs out of our control (like ScanWizard 5) produce PDF files with a /MediaBox equal to the size of the scanned area, not to the entire scanned page size. Such bad PDF files are also found on the web. 

The resulting PS files with a non-standard paper size print happily on non-PS printers with gs, but don't print on real PS printers. Instead the following page appears e.g on Lexmark Optra C710:
===============================================
ERROR: configurationerror
OFFENDING COMMAND: setpagedevice
ERRORINFO: Key = /PageSize Value = arraytype

STACK:

dicttype

===============================================

The minimal PDF file showing this problem can be obtained by doing a ps2pdf on the following PS file:
-----------------------------------------------
%!Adobe-PS
<< /PageSize [ 515 743 ] >> setpagedevice
/Helvetica findfont 28 scalefont setfont 0 setgray
50 50 moveto
(Test page) show
showpage
-----------------------------------------------

This behaviour is in fact documented in PostScript Language Reference Manual, 3rd ed., p. 434. Some workarounds that might be useful:

1) Add -sPAPERSIZE=... -dFIXEDMEDIA to gs options when printing. The "setpagedevice" command will still appear in the resulting PS file, but with arguments specifying a standard paper size. The page will print, but will not be centered.
2) Or (untested) add the following command somwhere at the beginning of the PS file produced by GS:

<< /Policy << /PageSize 3 >> >> setpagedevice

as described in PLRM, 3rd ed., p. 434.

I haven't found PS files with nonstandard paper size on the web, but this report applies to them also. Since we don't do a ps2ps on them, we must invent a different workaround.

Yes, I know that it's a bug in software that produces such PDF files, not in kghostview, but they are out of our control.
Comment 1 Sebastian Reitenbach 2005-05-18 16:32:53 UTC
Created attachment 11091 [details]
pdf file with non standard paper size (here the standard is A4)

i can confirm this bug. Just try to print out the pdf file.
 I'm using SuSE 9.1 and the SuSE KDE 3.4 rpms installed. I have kghostview 0.20
installed. I get the same error message. I also tried to print to a postscript
file, and then tried to use kprinter print.ps and got the same error, therefore
the postscript generation doesn't seem to work. printing this file from xpdf
works well.
Comment 2 Adrián Chaves (Gallaecio) 2012-10-14 20:50:47 UTC
Can you confirm whether or not this bug applies with Okular?
Comment 3 Alexander Patrakov 2012-10-15 12:47:01 UTC
Sorry, I am not a KDE user anymore, but I will test this if you recommend a KDE-based LiveCD or LiveDVD that supports printing.
Comment 4 Albert Astals Cid 2012-10-15 17:37:01 UTC
Hi Alexander, thanks for your offer. There are lots of KDE-based LiveCD, KUbuntu being one of them http://www.kubuntu.org/getkubuntu I understand that printing should work on the LiveCD but actually I have never tried it.

Thanks a lot for the offer to give it a try :-)
Comment 5 Alexander Patrakov 2012-10-16 05:17:48 UTC
I have done the following on a Kubuntu 12.04 LiveCD:

1. Installed a Generic PostScript printer on socket://127.0.0.1:9100
2. Created a test PDF file following my own instructions dated 2003-09-13 17:09:29 UTC
3. Started nc -l 127.0.0.1 9100 > dump.ps
4. Printed the test PDF file using Okular
5. Examined the dump.ps file using "less", with the following criteria: either the setpagedevice command should be redefined in the prolog, or there should be no "<< /PageSize [ 515 743 ] >> setpagedevice" line on the result.
6. Repeated the test using the original bad ps file.

The offending setpagedevice instruction is not in the resulting ps file when printing a pdf from Okular. Additionally, when printing a pdf, Okular inserts this, effectively redefining setpagedevice:

/pdfSetup {
  3 1 roll 2 array astore
  /setpagedevice where {
    pop 3 dict begin
      /PageSize exch def
      /ImagingBBox null def
      { /Duplex true def } if
    currentdict end setpagedevice
  } {
    pop pop
  } ifelse
} def

This is called as follows:

595 842 false pdfSetup

i.e. the original clearly-incompatible page size is not mentioned at all.

Or you may want to punt it and say that it is a bug in CUPS, because "printing" the bad ps file using lpr would fail due to setpagedevice.

I think I have a PostScript network printer near here (it is just not configured on my box because there is another, non-PostScript, printer closer to my desk), will test more and report the results.
Comment 6 Alexander Patrakov 2012-10-16 05:42:02 UTC
OK, tested with an HP laserJet 3055 configured as a generic PostScript printer. The default paper size is set to A4 in CUPS, and the Properties dialog in KDE also shows A4 as the desired paper size for the printer.

1. Printing test.ps (the file between the "---" markers in the original bug submission) using Okular results in the printer asking for the proper paper - i.e. the bug is still there for PS.

2. Printing test.pdf generated by "ps2pdf test.ps" using Okular just works on A4 paper - i.e. no bug for PDF.

3. Printing either test.ps or test.pdf using lpr results in the printer asking for the proper paper.
Comment 7 Adrián Chaves (Gallaecio) 2012-10-16 05:46:54 UTC
So the bug still applies. Thanks!
Comment 8 Justin Zobel 2021-03-09 23:59:20 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.