[poppler] poppler/PSOutputDev.cc poppler/PSOutputDev.h utils/pdftops.1 utils/pdftops.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Jun 4 10:51:06 PDT 2009


 poppler/PSOutputDev.cc |   31 +++++++++++++++++++++++++++++--
 poppler/PSOutputDev.h  |    4 +++-
 utils/pdftops.1        |   26 +++++++++++++++++++++-----
 utils/pdftops.cc       |   17 ++++++++++++-----
 4 files changed, 65 insertions(+), 13 deletions(-)

New commits:
commit 2cf9e6a2318b770ae62572944c687576d1801d31
Author: Till Kamppeter <till.kamppeter at gmail.com>
Date:   Thu Jun 4 19:48:42 2009 +0200

    Support multiple page sizes when converting to PS
    
    Fixes byg #19777

diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 7f60292..b0084af 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -21,6 +21,7 @@
 // Copyright (C) 2008 Koji Otani <sho at bbr.jp>
 // Copyright (C) 2008 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2009 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2009 Till Kamppeter <till.kamppeter at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -1274,6 +1275,7 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage,
   Object info, obj1;
 
   switch (mode) {
+  case psModePSOrigPageSizes:
   case psModePS:
     writePS("%!PS-Adobe-3.0\n");
     break;
@@ -1304,6 +1306,7 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage,
   writePS("%%DocumentSuppliedResources: (atend)\n");
 
   switch (mode) {
+  case psModePSOrigPageSizes:
   case psModePS:
     writePSFmt("%%DocumentMedia: plain {0:d} {1:d} 0 () ()\n",
 	       paperWidth, paperHeight);
@@ -3134,7 +3137,7 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {
   GBool landscape;
 
 
-  if (mode == psModePS) {
+  if (mode == psModePS || mode == psModePSOrigPageSizes) {
     GooString pageLabel;
     const GBool gotLabel = m_catalog->indexToLabel(pageNum -1, &pageLabel);
     if (gotLabel) {
@@ -3149,7 +3152,8 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {
     } else {
       writePSFmt("%%Page: {0:d} {1:d}\n", pageNum, seqPage);
     }
-    writePS("%%BeginPageSetup\n");
+    if (mode != psModePSOrigPageSizes)
+      writePS("%%BeginPageSetup\n");
   }
 
   // underlays
@@ -3162,6 +3166,29 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {
 
   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 --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 0aea502..ac2416c 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -18,6 +18,7 @@
 // Copyright (C) 2006-2008 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2007 Brad Hards <bradh at kde.org>
 // Copyright (C) 2009 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2009 Till Kamppeter <till.kamppeter at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -55,7 +56,8 @@ class Function;
 enum PSOutMode {
   psModePS,
   psModeEPS,
-  psModeForm
+  psModeForm,
+  psModePSOrigPageSizes
 };
 
 enum PSFileType {
diff --git a/utils/pdftops.1 b/utils/pdftops.1
index dfa07b3..45e8399 100644
--- a/utils/pdftops.1
+++ b/utils/pdftops.1
@@ -65,17 +65,30 @@ CID font embedding.
 Generate Level 3 separable PostScript.  The separation handling is the
 same as for \-level2Sep.
 .TP
+.B \-origpagesizes
+Generate a PostScript file with variable page sizes and orientations,
+taking for each page the size of the original page in the PDF file. 
+The PostScript file contains "<</PageSize [WIDTH HEIGHT]>> setpagedevice"
+lines in each page header, so that the paper input tray gets correctly
+changed on the printer. This option should be used when pdftops is used
+as a print filter. Any specification of the page size via \-paper,
+\-paperw, or \-paperh will get overridden as long as each page of the
+PDF file has a defined paper size.  No more than one of the mode options
+(\-origpagesizes, \-eps, \-form) may be given.
+.TP
 .B \-eps
 Generate an Encapsulated PostScript (EPS) file.  An EPS file contains
 a single image, so if you use this option with a multi-page PDF file,
 you must use \-f and \-l to specify a single page.  No more than one of
-the mode options (\-eps, \-form) may be given.
+the mode options (\-origpagesizes, \-eps, \-form) may be given.
 .TP
 .B \-form
 Generate a PostScript form which can be imported by software that
 understands forms.  A form contains a single page, so if you use this
 option with a multi-page PDF file, you must use \-f and \-l to specify a
-single page.  The \-level1 option cannot be used with \-form.
+single page.  The \-level1 option cannot be used with \-form.  No more
+than one of the mode options (\-origpagesizes, \-eps, \-form) may be
+given.
 .TP
 .B \-opi
 Generate OPI comments for all images and forms which have OPI
@@ -113,13 +126,16 @@ preload images and forms
 .BI \-paper " size"
 Set the paper size to one of "letter", "legal", "A4", or "A3".  This
 can also be set to "match", which will set the paper size to match the
-size specified in the PDF file.
+size specified in the PDF file. \-origpagesizes overrides this setting
+if the PDF file has defined page sizes.
 .TP
 .BI \-paperw " size"
-Set the paper width, in points.
+Set the paper width, in points. \-origpagesizes overrides this setting
+if the PDF file has defined page sizes.
 .TP
 .BI \-paperh " size"
-Set the paper height, in points.
+Set the paper height, in points. \-origpagesizes overrides this setting
+if the PDF file has defined page sizes.
 .TP
 .B \-nocrop
 By default, output is cropped to the CropBox specified in the PDF
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index 6801050..747063e 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -17,6 +17,7 @@
 //
 // Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2009 Till Kamppeter <till.kamppeter at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -74,6 +75,7 @@ static GBool level2 = gFalse;
 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 +117,8 @@ static const ArgDesc argDesc[] = {
    "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 +206,10 @@ int main(int argc, char *argv[]) {
     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 +229,10 @@ int main(int argc, char *argv[]) {
     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


More information about the poppler mailing list