You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Dip Narayan Sarkar <di...@outlook.com> on 2022/01/16 13:29:23 UTC
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
Re: Unable to set Page Size using setMediaBox on a PDF document created by PDFMergerUtility
Posted by Tilman Hausherr <TH...@t-online.de>.
Maybe you need to set the cropBox as well.
Tilman
Am 16.01.2022 um 14:29 schrieb Dip Narayan Sarkar:
>
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail:users-help@pdfbox.apache.org
RE: Unable to set Page Size using setMediaBox on a PDF document created by PDFMergerUtility
Posted by Dip Narayan Sarkar <di...@outlook.com>.
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<ma...@outlook.com>
Sent: 16 January 2022 18:59
To: users@pdfbox.apache.org<ma...@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