I am trying to write a PDF conversion that will take a pdf file containing 1-up portrait pages and create a new document but merge every 2 pages into one page with two layers
t

The following code will reduce the content by 50%, but I canβt figure out how to make a new page landscape by entering another page as a portrait and squirting into the top left and right center
public static void main(String[] args) throws IOException, DocumentException, COSVisitorException { scalePages("c:/pdf/in.pdf", "c:/pdf/out" + new Date().getTime() + ".pdf", 0.50f); } public static void scalePages(String inFile, String outFile, float scale ) throws IOException, COSVisitorException { PDDocument doc1 = null; try { doc1 = PDDocument.load( inFile ); List allPages = doc1.getDocumentCatalog().getAllPages(); for( int i=0; i<allPages.size(); i++ ) { PDPage page1 = (PDPage)allPages.get(i ); PDRectangle mediaBox = page1.getMediaBox(); float oldX = mediaBox.getUpperRightX(); float newX = oldX * scale; float oldY = mediaBox.getUpperRightY(); float newY = oldY * scale; mediaBox.setUpperRightX(newX); mediaBox.setUpperRightY(newY); PDFStreamParser parser = new PDFStreamParser(page1.getContents()); parser.parse(); List tokens = parser.getTokens(); tokens.add(0,new COSFloat(scale)); tokens.add(1,new COSInteger(0)); tokens.add(2,new COSInteger(0)); tokens.add(3,new COSFloat(scale)); tokens.add(4,new COSInteger(0)); tokens.add(5,new COSInteger(0)); tokens.add(6,PDFOperator.getOperator("cm")); PDStream newContents = new PDStream( doc1 ); ContentStreamWriter writer = new ContentStreamWriter( newContents.createOutputStream() ); writer.writeTokens( tokens ); newContents.addCompression(); page1.setContents(newContents);
therefore, the result is as follows

any pointers would be greatly appreciated
kabal source share