Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdftops CUPS filter (Poppler mode) does not conserve paper sizes of input file #3689

michaelrsweet opened this issue Oct 13, 2010 · 7 comments


Copy link

michaelrsweet commented Oct 13, 2010

Version: 1.5-current User: till.kamppeter

If I print a PDF document with pages of different sizes (for example A4 pages and one A3-sized fold-out page between them) the pages get all scaled to the default paper size (or the to the page size of the first page).

This scaling of the pages happens in the pdftops filter when the filter is built to use Poppler's pdftops utility for the conversion (I do not build with Ghostscript as the PostScript generated by Ghostscript has a lot of problems). Formerly, Poppler's pdftops utility did not support generating PostScript with varying paper sizes. This problem I have solved by adding the "-origpagesizes" option to the utility and this change got accepted by Poppler upstream ( Then I have applied the attached patch to the CUPS packages of Debian and Ubuntu so that the pdftops filter of CUPS uses the new option and now there PDFs with varying page sizes get printed correctly.

This gets more and more important as applications are switching to send PDF instead of PostScript to CUPS when printing, especially all KDE and many GNOME applications do so, and will send PDF from the next release on. Also when switching over to the PDF printing workflow ( the pdftops filter plays and important role for printing on PostScript printers.

The attached patch fixes pdftops to support documents with varying page sizes. It also adds a build-time check to verify that the installed Poppler is really new enough to contain the "-origpagesizes" option in its pdftops utility.

Copy link
Collaborator Author

michaelrsweet commented Oct 13, 2010 User: h.blischke

I just checked the poppler based pdftops 0.12.4 (from peppermint one) and found that using the option "-origpagesizes" does not properly preserve page independence:

The setpagedevice command in the PageSetup section should be emitted for every page of the PDF that has it's own MediaBox or CropBox, and these pages should bracketed by a save and restore statement. Otherwise changing the output order or other page reordering will lead to weird results.

Moreover, it the source PDF really contains pages of different sizes, how then is n-up printing handled?

Copy link
Collaborator Author

michaelrsweet commented Dec 9, 2010 User: mike


Please let me know when the Poppler folks fix the page independence issue.

Copy link
Collaborator Author

michaelrsweet commented Dec 9, 2010 User: till.kamppeter

Helge, can you give a file example with the correctly set page sizes and "save" and "restore" calls? Can you also tell how to make duplex printing correctly working when each page in the PostScript file requests its paper size? My first patch for Poppler had all pages requesting their paper size and then duplex got reset to the front side of each sheet, making the job coming out one-sided. So I changed it to request the paper size only if it changes (see

Copy link
Collaborator Author

michaelrsweet commented Dec 9, 2010 User: till.kamppeter

Reported page independence problem to Poppler:

Copy link
Collaborator Author

michaelrsweet commented Dec 10, 2010 User: h.blischke

First, in any case I'd through the PDF's pae nodes and page object dictionaries to evaluate the prevailing page size and use that as the default page size as defined by the pdfSetup procedure.

Then, if -origpagesizes is specified, I'd only specify a page specific page size if it differs from the overall page size. To preserve page independence (which is mandatory to allow page reordering), my suggestion is to insert save and restore statements as follows

%%Page: 1 1
%%PageBoundingBox: 0 0 432 288
%%PageOrientation: Landscape
userdict/PageSave save put % inserted save statement
<</PageSize [432 288]>> setpagedevice
0 0 432 288 re W

... page body goes here

userdict/PageSave get restore % inserted restore statement
%%Page: 2 2

In case of duplex printing, the save and restore could bracket a pair of subsequent pages (an odd and an even one), provided that both pages have the same page size (printing different page sizes onto the same sheet seems not quite reaonable, doesn't it?).

Nevertheless, preserving the original page sizes of a multi-sized PDF document and printing on a real printer is sort of a goal conflict - it is not compliant with number-up or printing or booklet making or the like. Moreover, many production printers implement finishing (binding or stapling etc.) sections of a job by bracketing these sections by save and restore and switching the finishing parameters by a setpagedevice statement immediately following the save (for the details see the device control sections of the PLRM).

Copy link
Collaborator Author

michaelrsweet commented May 6, 2011 User: mike

Fixed in Subversion repository.

I didn't include the change to only use level2 output - we should fix Poppler in this case.

Copy link
Collaborator Author

michaelrsweet commented May 6, 2011


#! /bin/sh /usr/share/dpatch/dpatch-run

poppler-based-pdftops-fixes.dpatch by

All lines beginning with `## DP:' are a description of the patch.

DP: No description.

diff -urNad cups-1.3.11~/config-scripts/cups-pdf.m4 cups-1.3.11/config-scripts/cups-pdf.m4
--- cups-1.3.11~/config-scripts/cups-pdf.m4 2009-03-12 22:34:21.000000000 +0100
+++ cups-1.3.11/config-scripts/cups-pdf.m4 2009-07-11 17:09:17.247024891 +0200
@@ -64,6 +64,12 @@

+if test "x$CUPS_PDFTOPS" != x; then

  • if $CUPS_PDFTOPS -h 2>&1 | grep -q -- -origpagesizes 2>/dev/null; then
  • fi

diff -urNad cups-1.3.11~/ cups-1.3.11/
--- cups-1.3.11~/ 2009-03-12 22:34:21.000000000 +0100
+++ cups-1.3.11/ 2009-07-11 17:09:17.247024891 +0200
@@ -440,6 +440,7 @@

#define CUPS_PDFTOPS "/usr/bin/pdftops"

diff -urNad cups-1.3.11~/filter/pdftops.c cups-1.3.11/filter/pdftops.c
--- cups-1.3.11~/filter/pdftops.c 2009-05-22 21:30:50.000000000 +0200
+++ cups-1.3.11/filter/pdftops.c 2009-07-11 17:11:12.447026151 +0200
@@ -303,7 +303,9 @@

  •  pdf_argv[pdf_argc++] = (char *)"-level3";
  •  /\* Do not emit PS Level 3 with Poppler, some HP PostScript printers
  •     do not like it. See */
  •  pdf_argv[pdf_argc++] = (char _)"-level2";

    pdf_argv[pdf_argc++] = (char *)"-dLanguageLevel=3";
    #endif /_ HAVE_PDFTOPS /
    @@ -389,7 +391,18 @@
    pdf_argv[pdf_argc++] = pdf_width;
    pdf_argv[pdf_argc++] = pdf_height;
    #endif /

  • }

  • else

  • {

  • /*
  •  \*  Use the page sizes of the original PDF document, this way documents
  •  \*  which contain pages of different sizes can be printed correctly
  •  */
  •  pdf_argv[pdf_argc++] = (char *)"-origpagesizes";


    #ifdef HAVE_PDFTOPS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant