/ Published in: Java

Generates two PDF documents and then overlays the second onto the first.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * @param args the command line arguments * @throws java.io.IOException */ PDDocument document1 = getFirstDoc(); PDDocument document2 = getSecondDoc(); Overlay overlay = new Overlay(); overlay.setInputPDF(document1); overlay.setAllPagesOverlayPDF(document2); overlay.overlay(ovmap); document1.save(""); document1.close(); document2.close(); } PDDocument document = new PDDocument(); PDPage page = new PDPage(PDRectangle.A4); document.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.addRect(0, 0, page.getMediaBox().getWidth(), page.getMediaBox().getHeight()); contentStream.fill(); contentStream.close(); return document; } PDDocument document = new PDDocument(); PDPage page = new PDPage(PDRectangle.A4); document.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.beginText(); contentStream.setFont(PDType1Font.TIMES_ROMAN, 12); contentStream.newLineAtOffset(25, 500); contentStream.showText("Hello World"); contentStream.endText(); contentStream.close(); return document; }
Comments
