A3 pdf file is cropped and printed on A4 paper

Bug #310575 reported by Joachim Schwender on 2008-12-22
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cups (Ubuntu)

Bug Description

Binary package hint: cups

I have several A3 sized pdf files that do not print correctly:
A3 landscape or portait format prints cropped to A4 paper. The landscape print is incorrectly rotated by 90° and then cropped to A4.
I print to a Postscript printer that understands PDF directly. If i upload the file directly to the printer via web interface (no cups in the processing) and let the printer decide on paper size, it prints correctly on A3 paper. I have tested this on 1.3.9-2ubuntu5 (Intrepid). On a server running Debian Lenny with cups 1.3.8-1lenny4, the same A3 files get scaled to A4 and printed on A4 paper, while the rotation seems correct for landscape and portrait.

Related branches

CVE References

Joachim Schwender (jschwender) wrote :
Joachim Schwender (jschwender) wrote :

This is the A3 portrait test file

Till Kamppeter (till-kamppeter) wrote :

For me your attached files print correctly if

1. You have installed the latest CUPS package (1.3.9-2ubuntu6). Note that 2ubuntu5 is broken. Do not use it.

2. Either the default paper size for your print queue is set to A3 or you select A3 paper size when sending the job.

The following test command lines gave always correct results for me (display the PostScript file /tmp/printout after each "lpr" call):

cupsctl LogLevel=debug
cupsctl FileDevice=yes
lpadmin -p a -E -v /tmp/printout -P /usr/share/ppd/openprinting/HP/HP_LaserJet_5200.ppd.gz -o PageSize=A3
lpr -P a A3landscape.pdf
lpr -P a A3portrait.pdf
lpadmin -p a -o PageSize=A4
lpr -P a -o PageSize=A3 A3landscape.pdf
lpr -P a -o PageSize=A3 A3portrait.pdf

If you print out of evince ("Document Viewer") you MUST choose the correct paper size (A3 here) under "Print Setup" before printing. Note also that evince does not remember the paper size which you have selected for your last printout. The problem is evince here, due to not very user-friendly handling of the page size.

Changed in cups:
importance: Undecided → Medium
status: New → Confirmed
Joachim Schwender (jschwender) wrote :

I can confirm that if you specify explicitly A3 it prints correctly. But is this the way it should be? If i print to Lenny cups queue or Sarge, i don't have to specify anything and i have mixed format PDFs in a directory and just do a
lpr -P xerox1 *.pdf
and each document is printed correctly, no matter if A3 or A4. This does not work with 2ubuntu6 version. I strongly disagree that it is a correct and expected print processing that If i print an A3 document it comes out cropped on A4 paper?? It can be better, the information is there, cups has just to use it, it it obviously worked as expected in other/older versions.

And i am not talking about printing from GUI applications like evince or acroread, just because you have to click on thousand buttons to get what you want, which makes it error prone.

Joachim Schwender (jschwender) wrote :

A combined printjob does also NOT print properly:
lpr -P xerox1 -o PageSize=A4 A4quer.pdf -o PageSize=A3 A3portrait.pdf -o PageSize=A4 quer7232.pdf
The last option wins. That is not the expected behavior.

Joachim Schwender (jschwender) wrote :

A document which contains a combination of A4,A3,A4 pages prints completely on A4 paper, the A3 page cropped. This is not good.

Till Kamppeter (till-kamppeter) wrote :

Can you rename your /usr/lib/cups/filter/pdftops file to /usr/lib/cups/filter/pdftops.orig and put the attached file into its place /usr/lib/cups/filter/pdftops? Make it world-executable ("chmod a+rx /usr/lib/cups/filter/pdftops").

Now try to print. does it solve your problem?

Till Kamppeter (till-kamppeter) wrote :
Joachim Schwender (jschwender) wrote :

Same result.

Can you do

sudo mv /usr/lib/cups/filter/pdftops.orig /usr/lib/cups/filter/pdftops
sudo mv /usr/lib/cups/filter/pdftopdf ~
sudo /etc/init.d/cups restart

Does it now print as expected?

Joachim Schwender (jschwender) wrote :

It still prints A3 pdf on A4 paper, but it scales it down instead of cropping.

Can you now try

cat > pdftopdf.dummy << EOF
cat \$6
sudo cp pdftopdf.dummy /usr/lib/cups/filter/pdftopdf
sudo chmod 755 /usr/lib/cups/filter/pdftopdf
sudo /etc/init.d/cups restart

and try to print again? Does this work now?

After you have tried out what happens after following the instructions of my previous comment, please try the following:

sudo cp/usr/lib/cups/filter/pdftopdf.orig /usr/lib/cups/filter/pdftopdf
lpr -o pdftopdfAutoRotate=false A3landscape.pdf

Joachim Schwender (jschwender) wrote :

After previous instructions it printed scaled on A4.
With the pdftopdf filter restored it prints A3 to A4 paper with scaling down. Rotations looks ok.

So this means that supplying "-o pdftopdfAutoRotate=false" restores the behavior of the old CUPS when the new filter chain is used?

I think I have found a fix for the bug in the pdftopdf CUPS filter. I attach an x86_64 binary of the fixed filter. If you need I can also make a 32-bit (i386) binary.


sudo cp pdftopdf.new /usr/lib/cups/filter/pdftopdf
sudo chmod 755 /usr/lib/cups/filter/pdftopdf

and try again. Is everything working for you now?

The source of the proposed fix, as a debdiff for the CUPS of current Intrepid, is attached.

The patch is also applied to the BZR repository of CUPS at Debian, so it will also go into the next Jaunty package.

Changed in cups:
status: Confirmed → Fix Committed
Joachim Schwender (jschwender) wrote :

The A3 files still print on A4 paper, but now cropping is lower left corner for landscape instead of center cropping like before. If i specify explicitly "-o PaperSize=A3" it chooses A3 paper and prints in correct scaling with correct rotation.

What do you get with

lpr -o pdftopdfAutoRotate=false A3landscape.pdf


Joachim Schwender (jschwender) wrote :

this option does not change anything with A3landscape.pdf or A4portrait.pdf. Also changing false to true does not change anything. Result is: it prints cropped to A4 paper.

I have found another bug in the pdftopdf filter which I have fixed now.Do

Download this new attachment and do again

sudo cp pdftopdf /usr/lib/cups/filter/pdftopdf
sudo chmod 755 /usr/lib/cups/filter/pdftopdf

and try again. Is everything working for you now?

Attached is the new debdiff to show the change in the source code.

I have also committed the new fix to the Debian BZR repository of CUPS now to get it into Jaumty.

Joachim Schwender (jschwender) wrote :

Result with this newest pdftopdf filter is that it scales A3 documents to A4 paper, landscape and portrait rotation works ok.
It still does not choose A3 paper.

I am not sure whether CUPS really supports paper size selection by the document. One could try to modify the pdftops and pstopdf filters to not impose the paper size from the PPD to the document

Now I think we should at least be on the state that we have the same behavior as in Hardy. Am I right?

Can you try the attached pdftops filter? I have modified it to keep the document's paper size as long as "fitplot" is NOT used.

Proceed the same way as with the pdftopdf filter.

Here is the source code patch which lead to the filter of the previous posting.

To be able to print also PostScript files you will have to replace also the pstopdf filter by this attachment.

Note: The attachments of the last three postings are probably not perfect. They will probably make a paper size given by the PPD or the command line completely ignored, at least when printing PostScript or PDF files (what usually comes from applications). Especially if your printer has A4 as standard size and you print a PostScript or PDF in Letter format, the printer can reject it.

But please test anyway, at least to see whether they lead to the desired behavior.

Then we could find a compromise, like imposing paper sizes from the command line but not from the PPD, and anyway, if you print with the "fitplot" option, the paper sizes get imposed again.

Joachim Schwender (jschwender) wrote :

1. Version 1.2 supported this, we have always been using this command line printing for these print jobs, it used to work as long as we had debian sarge with a self built vanilla v1.2 on the print server. It makes sense to support paper picking.
2. pdftops filter works partly: paper is picked properly for single print jobs with only one paper format, but a print file with a combination of A4 and A3 is complately printed to A4 paper with scale down. This is at least much better than cropping. Great! Thanks!
For my need here right now that functionality would be sufficient, but wouldn't it be good if combined formats are also printed correctly?
3. mentioned restrictions: Does that mean that if i print from an application i cannot choose the paper? That would also mean if i print an A3 document on a printer that is set to A4 as standard, i don't have to pick the paper and it is printed correctly? Our printers here would anyway reject a letter sized print job unless the printer is set to make it fit on a A4 paper, which is what i have set on all printers here.

Can you replace your pdftops filter by this one


Then the document page size should get conserved from the beginning to the end.

Joachim Schwender (jschwender) wrote :

single A3 pdfs are printed A3 paper, a combined A4+A3 pdf prints on A4 papaer with cropping.

Independent what pdftops filter is used, the tray seems to be generally selected by the size of the first page.

This means that the PostScript data stream produced when running the Ghostscript-based pdftops filter does not trigger tray changes when the page size changes. Pages are not scaled to fit into any given format.

The Poppler-based pdftops filter scales down all pages, in your last test not to the size given by CUPS as the filter is patched to not pass on the PPD or command line paper size. It seems to scale the pages to the size of the first page.

I have also tried to run

pdftops -noshrink -nocenter -nocrop combined.pdf

Then the output consists of all pages in original size but put onto A4 sheets in the orientation of the original pages. The A3 pages are cropped then. It seems that Poppler's pdftops is not able to produce documents with different paper sizes for the different pages.

The problem of the Ghostscript-based pdftops filter is caused by the following Ghostscript bug:


The bug is fixed in the latest SVN state of Ghostscript which will turn Ghostscript 8.64 on February 1st.

HPO (hpo) wrote :

I try to print on C5 envelopes.

original behaviour: render A4, crop to C5
with debdiff cups: render A4, scale to C5 (still incorrect)
with pdftops filter replacement: render to C5, print on A4 (printer asks for A4).

It seems my bug 318718 is a dup from this here. I will try to close that one.

I have packaged Ghostscript 8.64 (development snapshot of two weeks before release) for Jaunty now. Please test either on a Jaunty box or by starting a live CD/USB stick and then load the updates to get the new Ghostscript. Or install the packages on Intrepid. THen download them by going here:


choose your system architecture in the list on the right and after that follow the links to each binary package (on the right). You will at least need libgs8, ghostscript, and ghostscript-x. Install the packages with "sudo dpkg -i --force-overwrite --force-depends --force-conflicts <package name> ...".

Does printing of multiple-page-size files like combined.pdf work now (using the Ghostscript-based pdftops filter)?

To make your system consistent again after the test (if you have installed Jaunty's Ghostscript on Intrepid with "sudo dpkg -i --force-overwrite --force-depends --force-conflicts <package name> ..."), do

sudo dpkg -r --force-depends ghostscript ghostscript-x libgs8
sudo apt-get install --reinstall cups
sudo apt-get install ghostscript ghostscript-x libgs8

Joachim Schwender (jschwender) wrote :

combined.pdf still prints on A4 paper with cropping. The pdftopdf filter is still the binary that you proposed above, do i have to restore the original files??? pdftops is a shell script that you proposed, it looks to me like it uses ghostscript. I have installed jaunty package for amd64 on intrepid. It gave some complaints on dependancies for libsm6, libice6, libxt6 i don't know if that is relevant, but as my server is runing in a vserver environment without any X installed i guess it is irrelevant?

You do not have to restore anything. You should have my proposed pdftopdf and pdftops filters and Ghostscript 8.64.

Check whether Ghostscript works correctly running

gs -h
ldd /usr/bin/gs

These commands should not show any errors.

Try also running the command lines from


using combined.pdf as input file.

Joachim Schwender (jschwender) wrote :

OK, i have your pdftopdf and pdftops filters and above commands give no errors.
I converted the file and sent it to cups, the result again is that it prints on A4 paper with cropping.

Can you apply the patch shown in


to your


file and tell whether this makes your printer switching trays? Make sure that you are still with my newest pdftopdf filter, my newest Ghostscript-based script as pdftops filter and with Ghostscript 8.64.

If you have problems applying a patch, simply replace your /usr/share/ghostscript/8.64/Resource/Init/opdfread.ps with the attached file.

Joachim Schwender (jschwender) wrote :

This did not change anything.

Can you do the following:

gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pswrite -dDEVICEWIDTHPOINTS=595 -dDEVICEHEIGHTPOINTS=842 -sOUTPUTFILE=%stdout -dLanguageLevel=3 combined.pdf > combined.ps
nc -w1 <IP of your printer> 9100 < combined.ps

Are the trays changed correctly now?

PPD=/etc/cups/ppd/<name of your print queue>.ppd /usr/lib/cups/filter/pstops 1 1 1 1 '' combined.ps > combined2.ps
nc -w1 <IP of your printer> 9100 < combined2.ps

Are the tray correctly changed here?

Create a print queue identical to your existing one, but printing into a file:

cupsctl FileDevice=yes
lpadmin -p test -E -v /tmp/printout -P /etc/cups/ppd/<name of your print queue>.ppd

Print combined.pdf into this queue. Attach /tmp/printout to this bug report (you must "sudo chown" it to you to be able to open and copy it). Do you get automatic tray changes here?


sudo apt-get install netcat-traditional

if you do not have the "nc" command on your machine.

Joachim Schwender (jschwender) wrote :

1st trial did not change anything
2nd trial did also not change anything, but already the debug output from conversion has the same value for bboxx, pagew and pagel, which i expect different for each size.

ferro, that means that the PostScript which current Ghostscript and current Poppler are producing from PDF input does not trigger paper tray changes in your printer.

To investigate how PostScript has to look like so that tray changes will happen (so that one can improve filters in the future) can you please try the following:

Make some copies of the printout file which you have attached in the last posting.

Have a look at all four page headers, beginning with "%%Page" and ending with "%%EndPageSetup". Now we try two approaches to make the PostScript file switching trays:

1st approach: Remove the very first "%%PageBoundingBox:" lines directly after "%%Page". Do not remove the "%%PageBoundingBox:" lines after "%%BeginPageSetup".

2nd approach: Somewhere between "%%BeginPageSetup" and "%%EndPageSetup" setup add the line

<</PageSize [XXX YYY] /ImagingBBox null>> setpagedevice

replacing XXX and YYY by the two numbers in the beginning of the line which ends with "setpagesize".

3rd approach: Do both the 1st and the 2nd approach.

Edit always all four page headers as described. Send all the three approaches unfiltered (with the "nc ..." command line) to the printer. Which of these approaches make the printer switching trays.

If you can get hold on a machine with an old CUPS 1.2.x environment where the tray switching still worked, please make a copy of your print queue which prints into a file there, too (see my previous postings, "lpadmin -p test ....") and post the output PostScript file from there.

This is all to allow improvements of the filters in the future. For Intrepid we will make an SRU to at least get back to Hardy's behavior of scaling down the A3 pages to A4.

Joachim Schwender (jschwender) wrote :

ok, i am out next week and will do that after i returned...

Martin Pitt (pitti) wrote :

Accepted into intrepid-proposed, please test and give feedback here. Please see https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you in advance!

Changed in cups:
status: New → Fix Committed

ferro, note that the fix for Intrepid in -proposed is only to get Hardy's behavior of scaling down the A3 pages back, not for automatic tray change.

Automatic tray change we will get back in Jaunty. I have reported your problem to CUPS upstream:


Mike Sweet, author of CUPS, has solved it by imposing the page size to the document only if the page size is supplied on the command line. Otherwise the document's page size will be used.

I will also check the other filters and make them also behaving this way.

This means that then you should be able to print multiple-page size documents with automatic tray change with

lpr combined.pdf

and scale them to A4 with

lpr -o PageSize=A4 combined.pdf

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cups - 1.3.9-12

cups (1.3.9-12) experimental; urgency=low

  [ Till Kamppeter ]
  * debian/local/filters/pdf-filters/pdftopdf/P2PPage.cxx,
    debian/local/filters/pdf-filters/pdftopdf/pdftopdf.cxx: Do not reposition
    the pages when an automatic rotation did not actually take place and
    do not apply the page size and margins from the PPD file or the coomand
    line if no manipulations affecting the printout size are done (N-up,
    scaling, fitplot, ...). This caused LP: #310575.

  * debian/cups.postinst: Let the PPD files of the existing print queues get
    automatically updated after each installation of this package (if they
    use PPDs of this package).

  [ Marc Deslauriers ]
  * SECURITY UPDATE: denial of service by adding a large number of RSS
    subscriptions (Closes: #506180, LP: #298241)
    - debian/patches/CVE-2008-5183.dpatch: gracefully handle MaxSubscriptions
      being reached in scheduler/{ipp.c,subscriptions.c}
    - CVE-2008-5183

  [ Martin Pitt ]
  * pidfile.dpatch: Adapt to changes from MaxSubscriptions fix from

 -- Martin Pitt <email address hidden> Sun, 25 Jan 2009 12:05:44 +0100

Changed in cups:
status: Fix Committed → Fix Released

I have also reported


concerning automatic tray switching, as CUPS' pstops has also a bug.

The CUPS bug was rejected as Ghostscript did not actually produce correct DSC-conforming PostScript in the PDF-to-PostScript conversion by the pdftops (either my script or the filter of CUPS 1.4 which will come with Jaunty's CUPS package).

The Ghostscript upstream developers have accepted a last-minute fix for this into Ghostscript 8.64 today (GS is already in code freeze), so Jaunty will ship the tray switching on multiple-page-size documents already working.

If you want to test, please test with Jaunty and wait for the next CUPS and GS uploads.

I have now also reported a bug on Poppler, as Poppler's pdftops tool, which was used by Jaunty's pdftops CUPS filter formerly, does not support documents with pages of different sizes. It scales all pages to the size of the first page. Here is a link to the bug report:


I have now made printing documents with pages of different pages finally working in Jaunty's CUPS and in CUPS 1.4. With the next CUPS release in Jaunty you can print such documents out of applications or from the command line. The sizes of the pages are conserved (which would make your printer switching trays) as long as you do not supply the option "fitplot" or "fit-to-page" (in system-config-printer on the "Job Options" screen of the "Printer Properties" dialog the checkbox "Scale to fit" should NOT BE MARKED).

Martin Pitt (pitti) wrote :

Can anyone please test the current update in intrepid-proposed?

Joachim Schwender (jschwender) wrote :

I tested cups 1.3.9-2ubuntu7 from intrepid proposed.
All A3 prints are scaled down to A4 and printed to A4 paper. Rotation works ok.

OK, this is our expected behavior for Intrepid. So the SRU can be passed on to -updates.

ferro, the complete fix is done in Jaunty. Here a job with multiple page sizes will really switch input trays if the printer provides the requested sizes.

ferro, thank you very much for your cooperation.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cups - 1.3.9-2ubuntu7

cups (1.3.9-2ubuntu7) intrepid-proposed; urgency=low

  * debian/local/filters/pdf-filters/pdftopdf/P2PPage.cxx,
    debian/local/filters/pdf-filters/pdftopdf/pdftopdf.cxx: Do not reposition
    the pages when an automatic rotation did not actually take place and
    do not apply the page size and margins from the PPD file or the coomand
    line if no manipulations affecting the printout size are done (N-up,
    scaling, fitplot, ...). This caused LP: #310575.

 -- Till Kamppeter <email address hidden> Mon, 10 Jan 2008 13:19:55 +0100

Changed in cups:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.