From 196805d40ae74c83d3c049a382a3780390971534 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 13:38:41 +0200 Subject: [PATCH 1/9] Add JUnit and surefire deps for unit testing JUnit is the test framework, surefire will add test support to maven. --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 1a6b9a5..380bc32 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,12 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + @@ -54,5 +60,11 @@ picocli 4.7.5 + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + From 278bf0352d15dfeea12e226228436ede5e167600 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 13:38:52 +0200 Subject: [PATCH 2/9] Refactor scale check and add unit test --- .../pdftools/cli/cmds/FixPDFCommand.java | 6 +++- .../pdftools/cli/cmds/FixPDFCommandTest.java | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java diff --git a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java index 2010d88..51b5b0d 100644 --- a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java +++ b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java @@ -54,7 +54,7 @@ private static void fix(File input, File output) throws IOException { PDPageTree tree = pdf.getPages(); for (PDPage page : tree) { - if (page.getMediaBox().getWidth() > MAX_WIDTH || page.getMediaBox().getHeight() > MAX_HEIGHT) { + if (shouldPageBeRescaled(page)) { float fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); float fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); @@ -71,4 +71,8 @@ private static void fix(File input, File output) throws IOException { pdf.save(output); } } + + public static boolean shouldPageBeRescaled(PDPage page) { + return page.getMediaBox().getWidth() > MAX_WIDTH || page.getMediaBox().getHeight() > MAX_HEIGHT; + } } diff --git a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java new file mode 100644 index 0000000..e7051e1 --- /dev/null +++ b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java @@ -0,0 +1,33 @@ +package one.squeeze.pdftools.cli.cmds; + +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FixPDFCommandTest { + @Test + void testShouldPageBeRescaled_FalseOnA4Portrait() { + PDPage page = new PDPage(); + PDRectangle box = new PDRectangle(); + box.setUpperRightX(595); + box.setUpperRightY(841); + page.setMediaBox(box); + + assertFalse(FixPDFCommand.shouldPageBeRescaled(page)); + } + + @Test + @Disabled("Currently a bug forces scaling on landscape A4") + void testShouldPageBeRescaled_FalseOnA4Landscape() { + PDPage page = new PDPage(); + PDRectangle box = new PDRectangle(); + box.setUpperRightX(841); + box.setUpperRightY(595); + page.setMediaBox(box); + + assertFalse(FixPDFCommand.shouldPageBeRescaled(page)); + } +} From 7c71bc4f569c3a8027ea0806bf41a0d6995af439 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 13:40:24 +0200 Subject: [PATCH 3/9] Refactor scale factor calculation --- .../one/squeeze/pdftools/cli/cmds/FixPDFCommand.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java index 51b5b0d..185531c 100644 --- a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java +++ b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java @@ -55,10 +55,7 @@ private static void fix(File input, File output) throws IOException { for (PDPage page : tree) { if (shouldPageBeRescaled(page)) { - float fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); - float fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); - - float factor = Math.min(fWidth, fHeight); + float factor = calculateScaleFactor(page); PDPageContentStream contentStream = new PDPageContentStream(pdf, page, PDPageContentStream.AppendMode.PREPEND, false); contentStream.transform(Matrix.getScaleInstance(factor, factor)); @@ -72,6 +69,13 @@ private static void fix(File input, File output) throws IOException { } } + public static float calculateScaleFactor(PDPage page) { + float fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); + float fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); + + return Math.min(fWidth, fHeight); + } + public static boolean shouldPageBeRescaled(PDPage page) { return page.getMediaBox().getWidth() > MAX_WIDTH || page.getMediaBox().getHeight() > MAX_HEIGHT; } From 20af2cc59fbb23cc10adaa6a54e8c4bb08633d2c Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 13:40:51 +0200 Subject: [PATCH 4/9] Remove unused Printer variable --- src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java index 185531c..a351de0 100644 --- a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java +++ b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java @@ -50,7 +50,6 @@ public Integer call() throws Exception { private static void fix(File input, File output) throws IOException { try (PDDocument pdf = Loader.loadPDF(input)) { - PrinterJob job = PrinterJob.getPrinterJob(); PDPageTree tree = pdf.getPages(); for (PDPage page : tree) { From 36edfbaaa402d3d6b686f2ce5d1872819a9e8b68 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 13:42:38 +0200 Subject: [PATCH 5/9] Fix unwanted scaling on A4 landscape --- .../one/squeeze/pdftools/cli/cmds/FixPDFCommand.java | 9 ++++++++- .../one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java index a351de0..62a9bc6 100644 --- a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java +++ b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java @@ -76,6 +76,13 @@ public static float calculateScaleFactor(PDPage page) { } public static boolean shouldPageBeRescaled(PDPage page) { - return page.getMediaBox().getWidth() > MAX_WIDTH || page.getMediaBox().getHeight() > MAX_HEIGHT; + PDRectangle mediaBox = page.getMediaBox(); + boolean isPortrait = mediaBox.getWidth() < mediaBox.getHeight(); + + if (isPortrait) { + return mediaBox.getWidth() > MAX_WIDTH || mediaBox.getHeight() > MAX_HEIGHT; + } else { + return mediaBox.getWidth() > MAX_HEIGHT || mediaBox.getHeight() > MAX_WIDTH; + } } } diff --git a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java index e7051e1..2733c04 100644 --- a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java +++ b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java @@ -2,7 +2,6 @@ import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -20,7 +19,6 @@ void testShouldPageBeRescaled_FalseOnA4Portrait() { } @Test - @Disabled("Currently a bug forces scaling on landscape A4") void testShouldPageBeRescaled_FalseOnA4Landscape() { PDPage page = new PDPage(); PDRectangle box = new PDRectangle(); From 4bcfdbbcb7aa214adec8e2a5a8f0846d53bd8187 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 13:47:51 +0200 Subject: [PATCH 6/9] Run tests in CI --- .github/workflows/maven.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index aabe99c..9a9eabb 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,6 +21,17 @@ jobs: java-version: '17' distribution: 'temurin' cache: maven + + - name: Install deps with Maven + run: mvn install --file pom.xml + + - name: Test with Maven + run: mvn test --file pom.xml + + - name: Upload Test Report + uses: ScaCap/action-surefire-report@v1.7.2 + if: success() || failure() + - name: Build with Maven run: mvn -B package --file pom.xml From 09bfa7997ff49466e734923e8cde4323bbae4089 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 14:30:56 +0200 Subject: [PATCH 7/9] Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 380bc32..cc47b31 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ one.squeeze pdftools - 0.1.0 + 0.1.1 8 From c66087de9c69d5541a427a24165174f077619f87 Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 15:16:57 +0200 Subject: [PATCH 8/9] Refactor bugfix into a IScaler interface and implementations --- .../squeeze/pdftools/app/scale/IScaler.java | 12 +++++ .../pdftools/app/scale/NoopScaler.java | 11 +++++ .../squeeze/pdftools/app/scale/Scaler.java | 45 +++++++++++++++++++ .../pdftools/cli/cmds/FixPDFCommand.java | 41 ++++++++--------- .../pdftools/cli/cmds/FixPDFCommandTest.java | 12 +++-- 5 files changed, 95 insertions(+), 26 deletions(-) create mode 100644 src/main/java/one/squeeze/pdftools/app/scale/IScaler.java create mode 100644 src/main/java/one/squeeze/pdftools/app/scale/NoopScaler.java create mode 100644 src/main/java/one/squeeze/pdftools/app/scale/Scaler.java diff --git a/src/main/java/one/squeeze/pdftools/app/scale/IScaler.java b/src/main/java/one/squeeze/pdftools/app/scale/IScaler.java new file mode 100644 index 0000000..5d4dd66 --- /dev/null +++ b/src/main/java/one/squeeze/pdftools/app/scale/IScaler.java @@ -0,0 +1,12 @@ +package one.squeeze.pdftools.app.scale; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; + +import java.io.IOException; + +public interface IScaler { + + public void scale(PDDocument pdf, PDPage page) throws IOException; + +} diff --git a/src/main/java/one/squeeze/pdftools/app/scale/NoopScaler.java b/src/main/java/one/squeeze/pdftools/app/scale/NoopScaler.java new file mode 100644 index 0000000..bed2c06 --- /dev/null +++ b/src/main/java/one/squeeze/pdftools/app/scale/NoopScaler.java @@ -0,0 +1,11 @@ +package one.squeeze.pdftools.app.scale; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; + +import java.io.IOException; + +public class NoopScaler implements IScaler { + @Override + public void scale(PDDocument pdf, PDPage page) throws IOException {} +} diff --git a/src/main/java/one/squeeze/pdftools/app/scale/Scaler.java b/src/main/java/one/squeeze/pdftools/app/scale/Scaler.java new file mode 100644 index 0000000..da31782 --- /dev/null +++ b/src/main/java/one/squeeze/pdftools/app/scale/Scaler.java @@ -0,0 +1,45 @@ +package one.squeeze.pdftools.app.scale; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.util.Matrix; + +import java.io.IOException; + +public class Scaler implements IScaler { + + private final float factor; + + private final PDRectangle targetMediaBox; + + public Scaler(float factor, PDRectangle targetMediaBox) { + if (factor <= 0 || factor == 1) { + throw new IllegalArgumentException("Invalid factor: " + factor); + } + if (targetMediaBox == null) { + throw new IllegalArgumentException("Null targetMediaBox argument"); + } + + this.factor = factor; + this.targetMediaBox = targetMediaBox; + } + + @Override + public void scale(PDDocument pdf, PDPage page) throws IOException { + PDPageContentStream contentStream = new PDPageContentStream(pdf, page, PDPageContentStream.AppendMode.PREPEND, false); + contentStream.transform(Matrix.getScaleInstance(factor, factor)); + contentStream.close(); + + page.setMediaBox(targetMediaBox); + } + + public float getFactor() { + return factor; + } + + public PDRectangle getTargetMediaBox() { + return targetMediaBox; + } +} diff --git a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java index 62a9bc6..e4cfc0b 100644 --- a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java +++ b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java @@ -1,16 +1,16 @@ package one.squeeze.pdftools.cli.cmds; +import one.squeeze.pdftools.app.scale.IScaler; +import one.squeeze.pdftools.app.scale.NoopScaler; +import one.squeeze.pdftools.app.scale.Scaler; import org.apache.pdfbox.Loader; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageTree; import org.apache.pdfbox.pdmodel.common.PDRectangle; -import org.apache.pdfbox.util.Matrix; import picocli.CommandLine; -import java.awt.print.PrinterJob; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -53,36 +53,33 @@ private static void fix(File input, File output) throws IOException { PDPageTree tree = pdf.getPages(); for (PDPage page : tree) { - if (shouldPageBeRescaled(page)) { - float factor = calculateScaleFactor(page); - - PDPageContentStream contentStream = new PDPageContentStream(pdf, page, PDPageContentStream.AppendMode.PREPEND, false); - contentStream.transform(Matrix.getScaleInstance(factor, factor)); - contentStream.close(); - - page.setMediaBox(PDRectangle.A4); - } + IScaler scaler = buildScaler(page); + scaler.scale(pdf, page); } pdf.save(output); } } - public static float calculateScaleFactor(PDPage page) { - float fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); - float fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); - - return Math.min(fWidth, fHeight); - } - - public static boolean shouldPageBeRescaled(PDPage page) { + public static IScaler buildScaler(PDPage page) { PDRectangle mediaBox = page.getMediaBox(); boolean isPortrait = mediaBox.getWidth() < mediaBox.getHeight(); + boolean shouldScale = false; if (isPortrait) { - return mediaBox.getWidth() > MAX_WIDTH || mediaBox.getHeight() > MAX_HEIGHT; + shouldScale = mediaBox.getWidth() > MAX_WIDTH || mediaBox.getHeight() > MAX_HEIGHT; } else { - return mediaBox.getWidth() > MAX_HEIGHT || mediaBox.getHeight() > MAX_WIDTH; + shouldScale = mediaBox.getWidth() > MAX_HEIGHT || mediaBox.getHeight() > MAX_WIDTH; + } + if (!shouldScale) { + return new NoopScaler(); } + + // TODO: Take into account if portrait or landscape + float fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); + float fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); + float factor = Math.min(fWidth, fHeight); + + return new Scaler(factor, PDRectangle.A4); } } diff --git a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java index 2733c04..4848135 100644 --- a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java +++ b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java @@ -1,5 +1,7 @@ package one.squeeze.pdftools.cli.cmds; +import one.squeeze.pdftools.app.scale.IScaler; +import one.squeeze.pdftools.app.scale.NoopScaler; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.junit.jupiter.api.Test; @@ -8,24 +10,26 @@ class FixPDFCommandTest { @Test - void testShouldPageBeRescaled_FalseOnA4Portrait() { + void testBuildScaler_NoopOnA4Portrait() { PDPage page = new PDPage(); PDRectangle box = new PDRectangle(); box.setUpperRightX(595); box.setUpperRightY(841); page.setMediaBox(box); - assertFalse(FixPDFCommand.shouldPageBeRescaled(page)); + IScaler scaler = FixPDFCommand.buildScaler(page); + assertTrue(scaler instanceof NoopScaler); } @Test - void testShouldPageBeRescaled_FalseOnA4Landscape() { + void testBuildScaler_NoopOnA4Landscape() { PDPage page = new PDPage(); PDRectangle box = new PDRectangle(); box.setUpperRightX(841); box.setUpperRightY(595); page.setMediaBox(box); - assertFalse(FixPDFCommand.shouldPageBeRescaled(page)); + IScaler scaler = FixPDFCommand.buildScaler(page); + assertTrue(scaler instanceof NoopScaler); } } From 5ad40e83d23afeeae5bdd5e9560c5fda5f17b0cf Mon Sep 17 00:00:00 2001 From: fabiante Date: Wed, 11 Oct 2023 15:27:41 +0200 Subject: [PATCH 9/9] Take orientation into account when calculating aspect rations --- .../pdftools/cli/cmds/FixPDFCommand.java | 14 ++++- .../pdftools/cli/cmds/FixPDFCommandTest.java | 60 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java index e4cfc0b..f6be1e3 100644 --- a/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java +++ b/src/main/java/one/squeeze/pdftools/cli/cmds/FixPDFCommand.java @@ -75,9 +75,17 @@ public static IScaler buildScaler(PDPage page) { return new NoopScaler(); } - // TODO: Take into account if portrait or landscape - float fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); - float fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); + // Calculate scale factors. Depending on the orientation this requires division of height or width. + float fWidth = 1; + float fHeight = 1; + if (isPortrait) { + fWidth = MAX_WIDTH / page.getMediaBox().getWidth(); + fHeight = MAX_HEIGHT / page.getMediaBox().getHeight(); + } else { + fWidth = MAX_HEIGHT / page.getMediaBox().getWidth(); + fHeight = MAX_WIDTH / page.getMediaBox().getHeight(); + } + float factor = Math.min(fWidth, fHeight); return new Scaler(factor, PDRectangle.A4); diff --git a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java index 4848135..fc6dd0b 100644 --- a/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java +++ b/src/test/java/one/squeeze/pdftools/cli/cmds/FixPDFCommandTest.java @@ -2,6 +2,7 @@ import one.squeeze.pdftools.app.scale.IScaler; import one.squeeze.pdftools.app.scale.NoopScaler; +import one.squeeze.pdftools.app.scale.Scaler; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.junit.jupiter.api.Test; @@ -9,6 +10,15 @@ import static org.junit.jupiter.api.Assertions.*; class FixPDFCommandTest { + + + /** + * This constant is used to compare the expected output of factor calculation against 1. + * This is a nasty workarround, it would be better to improve the assertions using this constant. + * Either way, this currently works fine. + */ + public static final double TEN_PERCENT = 0.10000000149011612; + @Test void testBuildScaler_NoopOnA4Portrait() { PDPage page = new PDPage(); @@ -32,4 +42,54 @@ void testBuildScaler_NoopOnA4Landscape() { IScaler scaler = FixPDFCommand.buildScaler(page); assertTrue(scaler instanceof NoopScaler); } + + @Test + void testBuildScaler_NoopOnSmallerThanA4Portrait() { + PDPage page = new PDPage(); + PDRectangle box = new PDRectangle(); + box.setUpperRightX((float) 595 / 2); + box.setUpperRightY((float) 841 / 2); + page.setMediaBox(box); + + IScaler scaler = FixPDFCommand.buildScaler(page); + assertTrue(scaler instanceof NoopScaler); + } + + @Test + void testBuildScaler_NoopOnSmallerThanA4Landscape() { + PDPage page = new PDPage(); + PDRectangle box = new PDRectangle(); + box.setUpperRightX((float) 841 / 2); + box.setUpperRightY((float) 595 / 2); + page.setMediaBox(box); + + IScaler scaler = FixPDFCommand.buildScaler(page); + assertTrue(scaler instanceof NoopScaler); + } + + @Test + void testBuildScaler_ScalesLargePortrait() { + PDPage page = new PDPage(); + PDRectangle box = new PDRectangle(); + box.setUpperRightX(595 * 10); + box.setUpperRightY(841 * 10); + page.setMediaBox(box); + + Scaler scaler = (Scaler) FixPDFCommand.buildScaler(page); + assertEquals(TEN_PERCENT, scaler.getFactor()); + assertEquals(PDRectangle.A4, scaler.getTargetMediaBox()); + } + + @Test + void testBuildScaler_ScalesLargeLandscape() { + PDPage page = new PDPage(); + PDRectangle box = new PDRectangle(); + box.setUpperRightX(841 * 10); + box.setUpperRightY(595 * 10); + page.setMediaBox(box); + + Scaler scaler = (Scaler) FixPDFCommand.buildScaler(page); + assertEquals(TEN_PERCENT, scaler.getFactor()); + assertEquals(PDRectangle.A4, scaler.getTargetMediaBox()); + } }