/** * 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); }
PDPage imported = extractedDocument.importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox());
PDDocument samplePdf = null; try { samplePdf = PDDocument.load(PDF_PATH); PDPage page = (PDPage) samplePdf.getDocumentCatalog().getAllPages().get(0); for(int i = 0; i < COPIES; i++) { samplePdf.importPage(page); } samplePdf.save(SAVE_PATH); //$NON-NLS-1$ } catch (IOException e) { e.printStackTrace(); } catch (COSVisitorException e) { e.printStackTrace(); }
PDDocument source = PDDocument.load(resource); PDDocument output = new PDDocument(); PDPage page = source.getPages().get(0); output.importPage(page); output.save(new File(RESULT_FOLDER, "PageImportedFromAnnotationSample.Standard.pdf")); output.close();
populateB(); try (PDDocument doc = new PDDocument(); FileOutputStream stream = new FileOutputStream("bfilled.pdf")) { //importing the page will corrupt the fields doc.importPage((PDPage) pdfDocuments.get(0).getDocumentCatalog().getAllPages().get(0)); doc.save(stream); //save the whole document instead pdfDocuments.get(0).save(stream); } try (FileOutputStream stream = new FileOutputStream("bflattened.pdf")) { PdfStamper stamper = new PdfStamper(new PdfReader("bfilled.pdf"), stream); stamper.setFormFlattening(true); stamper.close(); }
System.out.println("page returned is: " + returnPage); System.out.println("Copy page"); newDocument.importPage(returnPage);
/** * 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); }
PDPage importedPage = outputDocument.importPage((PDPage)pages.get(j));
PDPage page = reportDocument.importPage(pp);
PDPage imported = extractedDocument.importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox());
PDPage imported = extractedDocument.importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox());
/** * 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; }