Got it now …
I also have to set:
page.setCropBox(PDRectangle. A3);

Thanks…

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Dip Narayan Sarkar<mailto:dipnaray...@outlook.com>
Sent: 16 January 2022 18:59
To: users@pdfbox.apache.org<mailto:users@pdfbox.apache.org>
Subject: Unable to set Page Size using setMediaBox on a PDF document created by 
PDFMergerUtility

Hi,
    Please see the sample code below:

In the final Output A_3.pdf , the page size does not change  to A3. Please let 
me know if I am missing something.

public static void main(String[] args) throws Exception {
    PDFMergerUtility pdfMergerUtil = new PDFMergerUtility();
    pdfMergerUtil.addSource("D:\\0PDFMERGE\\PDFBOX\\A.pdf");
    pdfMergerUtil.addSource("D:\\0PDFMERGE\\PDFBOX\\C.pdf");

    pdfMergerUtil.setDestinationFileName("D:\\0PDFMERGE\\PDFBOX\\AC_OUT.pdf");
    pdfMergerUtil.mergeDocuments(null);

    File mergedFile = new File("D:\\0PDFMERGE\\PDFBOX\\AC_OUT.pdf");
    PDDocument doc = PDDocument.load(mergedFile);

    for( PDPage page: doc.getPages()) {
      page.setMediaBox(PDRectangle.A3);
    }
    doc.save("D:\\0PDFMERGE\\PDFBOX\\A_3.pdf");
    doc.close();


  }

Strange thing though, if I use A6 instead of A3 the page size does change. 
Looks like the document generated by PDFMergerUtility  sets the MAX and does 
not allow to set beyond that , but allows shrinking the size.

BR,
Dip


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


Reply via email to