Please also add the following bug fix patches (they are both accepted into Poppler upstream):

https://bugs.freedesktop.org/show_bug.cgi?id=20420
  pdftops produces broken Postscript
  15_poppler-ps-output-broken-binary-encoding-fix.patch

https://bugs.freedesktop.org/show_bug.cgi?id=19777
  pdftops command line utility does not convert multiple-page-size
  documents correctly
  10_pdftops-multiple-page-size-support.patch

The first patch makes the CUPS pdftops filter reliably working also on PDF files with embedded images. The second allows converting PDF files with pages of different sizes so that the resulting PostScript file has the page sizes conserved. The patches are needed for correct printing with CUPS on PostScript and on many printers with manufacturer-supplied drivers.

diff -Nur -x '*.orig' -x '*~' poppler-0.11.0/poppler/PSOutputDev.cc poppler-0.11.0.new/poppler/PSOutputDev.cc
--- poppler-0.11.0/poppler/PSOutputDev.cc	2009-05-11 19:59:09.000000000 +0200
+++ poppler-0.11.0.new/poppler/PSOutputDev.cc	2009-06-03 14:34:12.000000000 +0200
@@ -1269,6 +1269,7 @@
   Object info, obj1;
 
   switch (mode) {
+  case psModePSOrigPageSizes:
   case psModePS:
     writePS("%!PS-Adobe-3.0\n");
     break;
@@ -1299,6 +1300,7 @@
   writePS("%%DocumentSuppliedResources: (atend)\n");
 
   switch (mode) {
+  case psModePSOrigPageSizes:
   case psModePS:
     writePSFmt("%%DocumentMedia: plain {0:d} {1:d} 0 () ()\n",
 	       paperWidth, paperHeight);
@@ -3122,7 +3124,7 @@
   GBool landscape;
 
 
-  if (mode == psModePS) {
+  if (mode == psModePS || mode == psModePSOrigPageSizes) {
     GooString pageLabel;
     const GBool gotLabel = m_catalog->indexToLabel(pageNum -1, &pageLabel);
     if (gotLabel) {
@@ -3137,7 +3139,8 @@
     } else {
       writePSFmt("%%Page: {0:d} {1:d}\n", pageNum, seqPage);
     }
-    writePS("%%BeginPageSetup\n");
+    if (mode != psModePSOrigPageSizes)
+      writePS("%%BeginPageSetup\n");
   }
 
   // underlays
@@ -3150,6 +3153,29 @@
 
   switch (mode) {
 
+  case psModePSOrigPageSizes:
+    x1 = (int)floor(state->getX1());
+    y1 = (int)floor(state->getY1());
+    x2 = (int)ceil(state->getX2());
+    y2 = (int)ceil(state->getY2());
+    width = x2 - x1;
+    height = y2 - y1;
+    if (width > height) {
+      landscape = gTrue;
+    } else {
+      landscape = gFalse;
+    }
+    writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", x1, y1, x2 - x1, y2 - y1);
+    writePS("%%BeginPageSetup\n");
+    writePSFmt("%%PageOrientation: {0:s}\n",
+	       landscape ? "Landscape" : "Portrait");
+    writePSFmt("<</PageSize [{0:d} {1:d}]>> setpagedevice\n", width, height);
+    writePS("pdfStartPage\n");
+    writePSFmt("{0:d} {1:d} {2:d} {3:d} re W\n", x1, y1, x2 - x1, y2 - y1);
+    writePS("%%EndPageSetup\n");
+    ++seqPage;
+    break;
+
   case psModePS:
     // rotate, translate, and scale page
     imgWidth = imgURX - imgLLX;
diff -Nur -x '*.orig' -x '*~' poppler-0.11.0/poppler/PSOutputDev.h poppler-0.11.0.new/poppler/PSOutputDev.h
--- poppler-0.11.0/poppler/PSOutputDev.h	2009-05-11 19:59:09.000000000 +0200
+++ poppler-0.11.0.new/poppler/PSOutputDev.h	2009-06-03 14:20:38.000000000 +0200
@@ -53,7 +53,8 @@
 enum PSOutMode {
   psModePS,
   psModeEPS,
-  psModeForm
+  psModeForm,
+  psModePSOrigPageSizes
 };
 
 enum PSFileType {
diff -Nur -x '*.orig' -x '*~' poppler-0.11.0/utils/pdftops.cc poppler-0.11.0.new/utils/pdftops.cc
--- poppler-0.11.0/utils/pdftops.cc	2008-11-08 20:00:30.000000000 +0100
+++ poppler-0.11.0.new/utils/pdftops.cc	2009-06-03 14:20:38.000000000 +0200
@@ -74,6 +74,7 @@
 static GBool level2Sep = gFalse;
 static GBool level3 = gFalse;
 static GBool level3Sep = gFalse;
+static GBool doOrigPageSizes = gFalse;
 static GBool doEPS = gFalse;
 static GBool doForm = gFalse;
 #if OPI_SUPPORT
@@ -115,6 +116,8 @@
    "generate Level 3 PostScript"},
   {"-level3sep",  argFlag,     &level3Sep,      0,
    "generate Level 3 separable PostScript"},
+  {"-origpagesizes",argFlag,   &doOrigPageSizes,0,
+   "conserve original page sizes"},
   {"-eps",        argFlag,     &doEPS,          0,
    "generate Encapsulated PostScript (EPS)"},
   {"-form",       argFlag,     &doForm,         0,
@@ -202,8 +205,10 @@
     fprintf(stderr, "Error: use only one of the 'level' options.\n");
     exit(1);
   }
-  if (doEPS && doForm) {
-    fprintf(stderr, "Error: use only one of -eps and -form\n");
+  if ((doOrigPageSizes ? 1 : 0) +
+      (doEPS ? 1 : 0) +
+      (doForm ? 1 : 0) > 1) {
+    fprintf(stderr, "Error: use only one of -origpagesizes, -eps, and -form\n");
     exit(1);
   }
   if (level1) {
@@ -223,9 +228,10 @@
     fprintf(stderr, "Error: forms are only available with Level 2 output.\n");
     exit(1);
   }
-  mode = doEPS ? psModeEPS
-               : doForm ? psModeForm
-                        : psModePS;
+  mode = doOrigPageSizes ? psModePSOrigPageSizes
+                         : doEPS ? psModeEPS
+                                 : doForm ? psModeForm
+                                          : psModePS;
   fileName = new GooString(argv[1]);
 
   // read config file
diff -Nur -x '*.orig' -x '*~' poppler-0.11.0/poppler/PSOutputDev.cc poppler-0.11.0.new/poppler/PSOutputDev.cc
--- poppler-0.11.0/poppler/PSOutputDev.cc	2009-06-04 18:20:49.000000000 +0200
+++ poppler-0.11.0.new/poppler/PSOutputDev.cc	2009-06-04 18:21:22.000000000 +0200
@@ -2705,6 +2705,9 @@
 	}
 	++col;
       }
+      if (c == (useASCIIHex ? '>' : '~') || c == EOF) {
+	break;
+      }
     }
     if (col > 225) {
       ++size;
@@ -2756,6 +2759,9 @@
 	  writePSChar(c);
 	  ++col;
 	}
+	if (c == (useASCIIHex ? '>' : '~') || c == EOF) {
+	  break;
+	}
       }
       // each line is: "dup nnnnn <~...data...~> put<eol>"
       // so max data length = 255 - 20 = 235

Reply via email to