addPage(importedPage); importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
PDPage imported = extractedDocument.importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
newPage.setMediaBox(page.getMediaBox()); newPage.setRotation(page.getRotation()); PDResources resources = page.getResources();
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);
(COSDictionary) cloner.cloneForNewDocument(page.getCOSObject())); newPage.setCropBox(page.getCropBox()); newPage.setMediaBox(page.getMediaBox()); newPage.setRotation(page.getRotation()); PDResources resources = page.getResources();
PDDocument document = PDDocument.load(resource); PDPage page = document.getDocumentCatalog().getPages().get(0); PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false); Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0); cs.transform(matrix); cs.close(); PDRectangle cropBox = page.getCropBox(); Rectangle rectangle = cropBox.transform(matrix).getBounds(); PDRectangle newBox = new PDRectangle((float)rectangle.getX(), (float)rectangle.getY(), (float)rectangle.getWidth(), (float)rectangle.getHeight()); page.setCropBox(newBox); page.setMediaBox(newBox);
private void createPage() throws Exception { processPictureData(); currentPage = new PDPage(); currentPage.setMediaBox(new PDRectangle(pageWidth, pageHeight)); stream = new PageContentStream(document, currentPage, true, true); }
private void writeGraphPage( GraphDisplay graphDisplay ) throws IOException { File tFile = File.createTempFile( "envisage", "png" ); graphDisplay.saveImage( new FileOutputStream( tFile ), "png", 1d ); BufferedImage img = ImageIO.read( tFile ); int w = img.getWidth(); int h = img.getHeight(); int inset = 40; PDRectangle pdRect = new PDRectangle( w + inset, h + inset ); PDPage page = new PDPage(); page.setMediaBox( pdRect ); doc.addPage( page ); PDJpeg xImage = new PDJpeg( doc, img ); PDPageContentStream contentStream = new PDPageContentStream( doc, page ); contentStream.drawImage( xImage, ( pdRect.getWidth() - w ) / 2, ( pdRect.getHeight() - h ) / 2 ); contentStream.close(); }
importedPage.setMediaBox( ((PDPage)pages.get(j)).findMediaBox() );
page.setMediaBox(new PDRectangle((int)(pdImage.getWidth() * scale), (int)(pdImage.getHeight() * scale))); contentStream.drawImage(pdImage, 0, 0, pdImage.getWidth()*scale, pdImage.getHeight()*scale);
mb.setUpperRightX(bodyBox.getLowerRight().getX()); mb.setUpperRightY(height - bodyBox.getUpperLeft().getY()); page.setMediaBox(mb);
PDDocument document = PDDocument.load(resource); PDPage page = document.getDocumentCatalog().getPages().get(0); PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false); Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0); cs.transform(matrix); cs.close(); PDRectangle cropBox = page.getCropBox(); float cx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2; float cy = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2; Point2D.Float newC = matrix.transformPoint(cx, cy); float tx = (float)newC.getX() - cx; float ty = (float)newC.getY() - cy; page.setCropBox(new PDRectangle(cropBox.getLowerLeftX() + tx, cropBox.getLowerLeftY() + ty, cropBox.getWidth(), cropBox.getHeight())); PDRectangle mediaBox = page.getMediaBox(); page.setMediaBox(new PDRectangle(mediaBox.getLowerLeftX() + tx, mediaBox.getLowerLeftY() + ty, mediaBox.getWidth(), mediaBox.getHeight()));
addPage(importedPage); importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
addPage(importedPage); importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
PDPage imported = extractedDocument.importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
PDPage imported = extractedDocument.importPage(page); imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
/** * <p> * Create a CSVTable object to be able to add CSV document to a Table. A * page needs to be passed to the constructor so the Template Cells can be * created. * </p> * * @param table {@link Table} * @param page {@link PDPage} * @throws IOException If there is an error releasing resources */ public DataTable(Table table, PDPage page) throws IOException { this.table = table; // Create a dummy pdf document, page and table to create template cells PDDocument ddoc = new PDDocument(); PDPage dpage = new PDPage(); dpage.setMediaBox(page.getMediaBox()); dpage.setRotation(page.getRotation()); ddoc.addPage(dpage); BaseTable dummyTable = new BaseTable(10f, 10f, 10f, table.getWidth(), 10f, ddoc, dpage, false, false); Row dr = dummyTable.createRow(0f); headerCellTemplate = dr.createCell(10f, "A", HorizontalAlignment.CENTER, VerticalAlignment.MIDDLE); dataCellTemplateEven = dr.createCell(10f, "A", HorizontalAlignment.LEFT, VerticalAlignment.MIDDLE); dataCellTemplateOdd = dr.createCell(10f, "A", HorizontalAlignment.LEFT, VerticalAlignment.MIDDLE); firstColumnCellTemplate = dr.createCell(10f, "A", HorizontalAlignment.LEFT, VerticalAlignment.MIDDLE); lastColumnCellTemplate = dr.createCell(10f, "A", HorizontalAlignment.LEFT, VerticalAlignment.MIDDLE); defaultCellTemplate = dr.createCell(10f, "A", HorizontalAlignment.LEFT, VerticalAlignment.MIDDLE); setDefaultStyles(); ddoc.close(); }
/** * 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; }
newMediaBox.setUpperRightX(mediaBox.getUpperRightX()); newMediaBox.setUpperRightY(mediaBox.getUpperRightY() + resize); myPage.setMediaBox(newMediaBox);
newPage.setMediaBox(page.getMediaBox()); newPage.setRotation(page.getRotation()); PDResources resources = page.getResources();