On June 11 I have proposed two bug fix patches for the Debian package of Poppler. One of them needs some additional changes to correctly work. So do not use the

10_pdftops-multiple-page-size-support.patch

which I have attached to this bug report earlier, but the patch attached to this e-mail. See the bug reports

https://bugs.freedesktop.org/show_bug.cgi?id=19777
https://bugs.launchpad.net/ubuntu/jaunty/+source/poppler/+bug/382379

for more about this new patch.

Thanks in advance.

   Till
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-22 16:40:04.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,9 @@
   writePS("%%DocumentSuppliedResources: (atend)\n");
 
   switch (mode) {
+  case psModePSOrigPageSizes:
+    prevWidth = 0;
+    prevHeight = 0;
   case psModePS:
     writePSFmt("%%DocumentMedia: plain {0:d} {1:d} 0 () ()\n",
 	       paperWidth, paperHeight);
@@ -3122,7 +3132,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 +3147,8 @@
     } else {
       writePSFmt("%%Page: {0:d} {1:d}\n", pageNum, seqPage);
     }
-    writePS("%%BeginPageSetup\n");
+    if (mode != psModePSOrigPageSizes)
+      writePS("%%BeginPageSetup\n");
   }
 
   // underlays
@@ -3150,6 +3161,35 @@
 
   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");
+    if ((width != prevWidth) || (height != prevHeight)) {
+      // Set page size only when it actually changes, as otherwise Duplex
+      // printing does not work
+      writePSFmt("<</PageSize [{0:d} {1:d}]>> setpagedevice\n", width, height);
+      prevWidth = width;
+      prevHeight = 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-22 16:40:04.000000000 +0200
@@ -53,7 +53,8 @@
 enum PSOutMode {
   psModePS,
   psModeEPS,
-  psModeForm
+  psModeForm,
+  psModePSOrigPageSizes
 };
 
 enum PSFileType {
@@ -333,6 +334,10 @@
   PSOutMode mode;		// PostScript mode (PS, EPS, form)
   int paperWidth;		// width of paper, in pts
   int paperHeight;		// height of paper, in pts
+  int prevWidth;		// width of previous page
+                                // (only psModePSOrigPageSizes output mode)
+  int prevHeight;		// height of previous page
+                                // (only psModePSOrigPageSizes output mode)
   int imgLLX, imgLLY,		// imageable area, in pts
       imgURX, imgURY;
   GBool preload;		// load all images into memory, and
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-22 16:39:56.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

Reply via email to