Bug 690421 - "pdfwrite" output device uses default paper size instead of page size(s) of the document
Summary: "pdfwrite" output device uses default paper size instead of page size(s) of t...
Status: RESOLVED INVALID
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Writer (show other bugs)
Version: 8.64
Hardware: All All
: P4 major
Assignee: Ken Sharp
URL: https://bugs.launchpad.net/bugs/357732
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-16 04:02 UTC by Till Kamppeter
Modified: 2009-04-16 13:59 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
flphoto-small-print.ps (103.70 KB, application/postscript)
2009-04-16 04:39 UTC, Till Kamppeter
Details
testpage-cups.ps (28.45 KB, application/postscript)
2009-04-16 05:48 UTC, Ken Sharp
Details
testpage-a4.ps (149.20 KB, application/postscript)
2009-04-16 06:42 UTC, Till Kamppeter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Till Kamppeter 2009-04-16 04:02:44 UTC
On Ubuntu Intrepid and newer CUPS works with a PDF-based printing workflow:

https://www.linuxfoundation.org/en/OpenPrinting/PDF_as_Standard_Print_Job_Format

This means all incoming files are converted to PDF (if they are not PDF already)
and processed in PDF format.

If an incoming file is PostScript it gets converted by the pstopdf CUPS filter from

http://www.openprinting.org/download/printing/pdf-printing/pstopdf

This filter converts the PostScript files with the ps2pdf13 script which comes
as part of Ghostscript.

I have a PostScript file which contains a bounding box (4x6 photo, attached) and
this displays correctly with gv and the "bbox" output device returns the correct
bounding box.

If I convert the file to PDF with "ps2pdf13" I get the photo in the lower left
corner of an A4 page (default paper size in /etc/papersize). Same happens when I
send it to the printer, which leads to only a part of the photo getting on 4x6
paper in my printer.

The same problem was also reported by a Ubuntu user. See

https://bugs.launchpad.net/bugs/357732

What I expect is that ps2pdf13 conserves the size of each page, so that the PDF
file has always the same page sizes as the incoming PostScript file. This makes
automated conversion (here in print queues) and handling of multiple-page-size
documents trivial.

If you have to stick to fixed paper sizes for all output pages (default size or
size given on command line) for compatibility with Acrobat Distiller, please
provide a "-dConservePageSizes" option to optionally allow conserving the input
paper sizes for use cases as my print filter.
Comment 1 Till Kamppeter 2009-04-16 04:39:37 UTC
Created attachment 4934 [details]
flphoto-small-print.ps

Print output of FL-Photo: A photo in 4x6 format
Comment 2 Alex Cherepanov 2009-04-16 05:33:57 UTC
Ghostscript works as designed.

The sample file doesn't set the page size and Ghostscript uses default page
size, usually, US Letter. Distiller also uses US Letter. There's nothing to
fix here.

The file has the following DSC comments:
%!PS-Adobe-3.0
%%BoundingBox: 0 0 288 432
%%Creator: flPhoto v1.3.1

i.e. is is not a EPS file. The BoundingBox comment in PS file indicates the
marked area on the page, rather than the media size. For multi-page documents
BoundingBox is defined as thee union of the page boxes, which doesn't
correspond to any real box on any page.

The use of BoundingBox in PS files to set the initial page size is likely to
break other files.

The bug report should be filed against "flPhoto v1.3.1" that relies on default
page size.
Comment 3 Ken Sharp 2009-04-16 05:48:57 UTC
Created attachment 4935 [details]
testpage-cups.ps

Alex, I've been discussing the problem with Till on IRC. I agree completely
with the phot file. However the bug report from the Ubuntu user seems
different. The job apparently does contain a /PageSize, but we seem to be
ignoring it. 

Possibly there is something in the job (produced initially by pswrite!) which
is obscuring the request. Setting the PageSize Policy to 2 might be the
problem.

I've attached the job from the Ubuntu report here, but haven't had a chance to
debug it yet, I'm currently running a full pdfwrite regression test, which
takes ages....
Comment 4 Till Kamppeter 2009-04-16 06:42:27 UTC
Created attachment 4936 [details]
testpage-a4.ps

Original Ubuntu test page in A4
Comment 5 Ken Sharp 2009-04-16 06:53:28 UTC
Alex has pointed out that the output from pswrite contains :

612 792 /letter setpagesize

Which sets the media to Letter, since this comes *after* the page size request
(from a PPD ?) for A4, it takes precedence. Because the PostScript file is the
result of multiple conversions by CUPS, somewhere along the line the job has
been created for Letter media. Selecting A4 media will not alter the fact that
it was originally prepared for Letter.

The original file (testpage-a4.ps) does not contain any media selection requests
(though it does contain comments about selecting A4 there are no requests and
the job is not EPS, so the comments are ignored). As a result any conversion
will use the default media size of Letter.

This of course leads to all later conversions using letter media.

I don't think there is a Ghostscript bug here, the bug is really in the
application generating the original PostScript which does not request any media.

This is the same problem as the photo uploaded by Till, no media selection
requests. The bug is in the original PostScript, not Ghostscript's handling of it.

It *is* possible to add DSC comment parsing handling, CUPS should either do this
itself (as other DSC parsers do) or add a prologue which will convert
%%BoundingBox comments into PageSize requests.
Comment 6 Till Kamppeter 2009-04-16 13:57:46 UTC
Problem solved in the CUPS filters. pstopdf applies the PageSize setting from
CUPS (from the filter command line and if not supplied there from the PPD file)
to the Ghostscript command line now ("-dDEVICEWIDTHPOINTS
=237 -dDEVICEHEIGHTPOINTS=525", numbers from *PaperDimension line in PPD). This
sets a useful default for PostScript files without PageSize request, either the
size the user has chosen in the printing dialog or the size set as printer
default by the admin. Multiple-page-size documents are expected to have
appropriate page size requests and with these they print correctly.
Comment 7 Till Kamppeter 2009-04-16 13:59:15 UTC
Thank you for your help, Ken and Alex, it helped me to find the solution for the
problem.