private void overlayPage(PDPage page, LayoutPage layoutPage, COSArray array) throws IOException { PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); page.setResources(resources); } COSName xObjectId = createOverlayXObject(page, layoutPage, layoutPage.overlayContentStream); array.add(createOverlayStream(page, layoutPage, xObjectId)); }
/** * Interface to start processing a new page. * * @param page The page that is about to get processed. * * @throws IOException If there is an error creating the new document. */ protected void processPage(PDPage page) throws IOException { createNewDocumentIfNecessary(); PDPage imported = getDestinationDocument().importPage(page); imported.setResources(page.getResources()); // remove page links to avoid copying not needed resources processAnnotations(imported); }
sourcePage.setResources(resources);
newPage.setResources(new PDResources( (COSDictionary) cloner.cloneForNewDocument(resources))); newPage.setResources(new PDResources());
page.setResources(resources); try
imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
newPage.setResources(new PDResources((COSDictionary) cloner.cloneForNewDocument(resources))); newPage.setResources(new PDResources());
PDPage imported = getDestinationDocument().importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); // only the resources of the page will be copied imported.setResources(page.getResources()); imported.setRotation(page.getRotation()); // remove page links to avoid copying not needed resources processAnnotations(imported);
page.setResources(resources);
private void overlayPage(PDPage page, LayoutPage layoutPage, COSArray array) throws IOException { PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); page.setResources(resources); } COSName xObjectId = createOverlayXObject(page, layoutPage, layoutPage.overlayContentStream); array.add(createOverlayStream(page, layoutPage, xObjectId)); }
/** * Interface to start processing a new page. * * @param page The page that is about to get processed. * * @throws IOException If there is an error creating the new document. */ protected void processPage(PDPage page) throws IOException { createNewDocumentIfNecessary(); PDPage imported = getDestinationDocument().importPage(page); imported.setResources(page.getResources()); // remove page links to avoid copying not needed resources processAnnotations(imported); }
/** * Interface to start processing a new page. * * @param page The page that is about to get processed. * * @throws IOException If there is an error creating the new document. */ protected void processPage(PDPage page) throws IOException { createNewDocumentIfNecessary(); PDPage imported = getDestinationDocument().importPage(page); imported.setResources(page.getResources()); // remove page links to avoid copying not needed resources processAnnotations(imported); }
importedPage.setMediaBox( ((PDPage)pages.get(j)).findMediaBox() ); importedPage.setResources( ((PDPage)pages.get(j)).getResources() ); importedPage.setRotation( ((PDPage)pages.get(j)).findRotation() );
page.setResources(newResources);
page.setResources(new PDResources());
PDDocument source = PDDocument.loadNonSeq(SOURCE, null); List<PDPage> pages = source.getDocumentCatalog().getAllPages(); PDDocument target = new PDDocument(); PDPage page = new PDPage(); PDRectangle cropBox = page.findCropBox(); page.setResources(new PDResources()); target.addPage(page); PDFormXObject xobject = importAsXObject(target, pages.get(0)); page.getResources().addXObject(xobject, "X"); PDPageContentStream content = new PDPageContentStream(target, page); AffineTransform transform = new AffineTransform(0, 0.5, -0.5, 0, cropBox.getWidth(), 0); content.drawXObject(xobject, transform); transform = new AffineTransform(0.5, 0.5, -0.5, 0.5, 0.5 * cropBox.getWidth(), 0.2 * cropBox.getHeight()); content.drawXObject(xobject, transform); content.close(); target.save(TARGET); target.close(); source.close();
if(resources == null ) { resources = new PDResources(new COSDictionary()); targetPage.setResources(resources);
imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
/** * Output a PDF with as many pages as there are interesting areas in the * input document */ @Override public PDDocument extract() throws IOException { PDDocument extractedDocument = new PDDocument(); extractedDocument.setDocumentInformation(sourceDocument.getDocumentInformation()); extractedDocument.getDocumentCatalog().setViewerPreferences( sourceDocument.getDocumentCatalog().getViewerPreferences()); @SuppressWarnings("unchecked") List<PDPage> pages = sourceDocument.getDocumentCatalog().getAllPages(); int pageCounter = 1; for (PDPage page : pages) { if (pageCounter >= startPage && pageCounter <= endPage) { List<PDRectangle> zoomedFragments = getFragments(page); for (PDRectangle fragment : zoomedFragments) { PDPage outputPage = extractedDocument.importPage(page); outputPage.setCropBox(fragment); outputPage.setMediaBox(page.getMediaBox()); outputPage.setResources(page.findResources()); outputPage.setRotation(page.findRotation()); // TODO: rotate the page in landscape mode is width > height } } pageCounter++; } return extractedDocument; }