I have a test where I do:

try (PDDocument document = Loader.loadPDF(new 
ClassPathResource("/A5.pdf").getFile())) {
    PDPage page = document.getPage(0);

    assertTrue(isStandardPageSize(page.getMediaBox(), A5));
    assertTrue(isStandardPageSize(page.getCropBox(), A5));
    assertTrue(isStandardPageSize(page.getTrimBox(), A5));

After migrating, it fails on page.getTrimBox()

java.lang.NullPointerException: Cannot invoke 
"org.apache.pdfbox.pdmodel.common.PDRectangle.getWidth()" because "box" is null

Under pdfbox 2.0.26 the code worked fine. It was:

        try (PDDocument document = PDDocument.load(new 
ClassPathResource("/A5.pdf").getInputStream())) {

    PDPage page = document.getPage(0);

    assertTrue(isStandardPageSize(page.getMediaBox(), A5));
    assertTrue(isStandardPageSize(page.getCropBox(), A5));
    assertTrue(isStandardPageSize(page.getTrimBox(), A5));

So, MediaBox and Cropbox still work but not Trimbox.

Reply via email to