diff options
-rw-r--r-- | utils/pdftoppm.1 | 3 | ||||
-rw-r--r-- | utils/pdftoppm.cc | 22 |
2 files changed, 19 insertions, 6 deletions
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 ) { |