I am concatenating multiple PDF files together. The dimensions of each input PDF file is out of my control.
Code examples are a little tricky as I am actually working in Clojure but I can give something close.
So right now imagine I am creating an inital page in a blank document. I then iterate over additional documents and begin adding their pages into the new document. This appears to work fine when pages are all A4 but I have an input which has a custom MediaBox.
Document base = new Document();
// For this demo I'm not going to use this
Page initialPage = base.getPages().add();
// Now I want to add an unusual landscape page
Page landscape = base.getPages().add();
// And give it a large landscape media box
Rectangle mediaBox = new Rectangle(0d, 0d, 1200d, 500d);
landscape.setMediaBox(mediaBox);
// once saved the media box changes and
// 2 portrait pages remain with media boxes
// of (0,0) (595, 842)
base.save("path/to/output.pdf");
How can I maintain the original Media/Crop/Bleed/Art boxes?
edit: I am using version 20.10 (java)