[poppler] utils/pdftoppm.1 utils/pdftoppm.cc

William Bader williambader at hotmail.com
Thu Dec 5 18:12:17 UTC 2019


Should this also be added to pdftocairo?
________________________________
From: poppler <poppler-bounces at lists.freedesktop.org> on behalf of GitLab Mirror <gitlab-mirror at kemper.freedesktop.org>
Sent: Thursday, December 5, 2019 7:03 AM
To: poppler at lists.freedesktop.org <poppler at lists.freedesktop.org>
Subject: [poppler] utils/pdftoppm.1 utils/pdftoppm.cc

utils/pdftoppm.1  |    3 +++
 utils/pdftoppm.cc |   22 ++++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

New commits:
commit 311db0b2de9a63d240d19bb90ba95a78f7856388
Author: corentinfoucault <corentinf at free.fr>
Date:   Thu Dec 5 12:03:56 2019 +0000

    [PdfToPpm] Add an option to scale before rotate

    -scale-dimension-before-rotation

diff --git a/utils/pdftoppm.1 b/utils/pdftoppm.1
index 79d78f4b..56808cd0 100644
--- a/utils/pdftoppm.1
+++ b/utils/pdftoppm.1
@@ -62,6 +62,9 @@ Scales each page vertically to fit in scale-to-y pixels. If scale-to-x
 is set to -1, the horizontal size will determined by the aspect ratio
 of the page.
 .TP
+.B \-scale-dimension-before-rotation
+Swaps horizontal and vertical size for a rotated (landscape) pdf before scaling instead of after.
+.TP
 .BI \-x " number"
 Specifies the x-coordinate of the crop area top left corner
 .TP
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 6a6acacb..aac1f743 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -74,6 +74,7 @@ static int lastPage = 0;
 static bool printOnlyOdd = false;
 static bool printOnlyEven = false;
 static bool singleFile = false;
+static bool scaleDimensionBeforeRotation = false;
 static double resolution = 0.0;
 static double x_resolution = 150.0;
 static double y_resolution = 150.0;
@@ -128,6 +129,8 @@ static const ArgDesc argDesc[] = {
    "print only even pages"},
   {"-singlefile", argFlag,  &singleFile,   0,
    "write only the first page and do not add digits"},
+  {"-scale-dimension-before-rotation", argFlag,  &scaleDimensionBeforeRotation,   0,
+   "for rotated pdf, resize dimensions before the rotation"},

   {"-r",      argFP,       &resolution,    0,
    "resolution, in DPI (default is 150)"},
@@ -218,6 +221,11 @@ static const ArgDesc argDesc[] = {
   {}
 };

+static bool needToRotate(int angle)
+{
+    return (angle == 90) || (angle == 270);
+}
+
 static bool parseJpegOptions()
 {
   //jpegOpt format is: <opt1>=<val1>,<opt2>=<val2>,...
@@ -395,7 +403,7 @@ int main(int argc, char *argv[]) {
   bool ok;
   int exitCode;
   int pg, pg_num_len;
-  double pg_w, pg_h, tmp;
+  double pg_w, pg_h;

   Win32Console win32Console(&argc, &argv);
   exitCode = 99;
@@ -558,6 +566,9 @@ int main(int argc, char *argv[]) {
       pg_h = doc->getPageMediaHeight(pg);
     }

+    if (scaleDimensionBeforeRotation && needToRotate(doc->getPageRotate(pg)))
+      std::swap(pg_w, pg_h);
+
     if (scaleTo != 0) {
       resolution = (72.0 * scaleTo) / (pg_w > pg_h ? pg_w : pg_h);
       x_resolution = y_resolution = resolution;
@@ -575,11 +586,10 @@ int main(int argc, char *argv[]) {
     }
     pg_w = pg_w * (x_resolution / 72.0);
     pg_h = pg_h * (y_resolution / 72.0);
-    if ((doc->getPageRotate(pg) == 90) || (doc->getPageRotate(pg) == 270)) {
-      tmp = pg_w;
-      pg_w = pg_h;
-      pg_h = tmp;
-    }
+
+    if (!scaleDimensionBeforeRotation && needToRotate(doc->getPageRotate(pg)))
+      std::swap(pg_w, pg_h);
+
     if (ppmRoot != nullptr) {
       const char *ext = png ? "png" : (jpeg || jpegcmyk) ? "jpg" : tiff ? "tif" : mono ? "pbm" : gray ? "pgm" : "ppm";
       if (singleFile && !forceNum ) {
_______________________________________________
poppler mailing list
poppler at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20191205/73dd66ca/attachment.html>


More information about the poppler mailing list