page.setRotation(0); AngleCollector angleCollector = new AngleCollector(); angleCollector.setStartPage(p); page.setRotation(rotation);
page.setRotation(0); page.setRotation(rotation);
importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
PDPage page = new PDPage(); document.addPage(page); page.setRotation(90); PDPageContentStream contentStream = new PDPageContentStream(document, page); int x = 150; int y = 300; // draw unrotated contentStream.drawXObject(ximage, x, y, ximage.getWidth() / 2, ximage.getHeight() / 2); // draw 90° rotated, placed on the right of the first image AffineTransform at = new AffineTransform(ximage.getHeight() / 2, 0, 0, ximage.getWidth() / 2, x + ximage1.getWidth(), y); at.rotate(Math.toRadians(90)); contentStream.drawXObject(ximage, at);
newPage.setRotation(page.getRotation()); PDResources resources = page.getResources(); if (resources != null)
PDPage page = new PDPage(PDRectangle.A4); page.setRotation(90); doc.addPage(page); PDRectangle pageSize = page.getMediaBox(); float pageWidth = pageSize.getWidth(); PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, false); // add the rotation using the current transformation matrix // including a translation of pageWidth to use the lower left corner as 0,0 reference contentStream.transform(new Matrix(0, 1, -1, 0, pageWidth, 0)); (...)
newPage.setCropBox(page.getCropBox()); newPage.setMediaBox(page.getMediaBox()); newPage.setRotation(page.getRotation()); PDResources resources = page.getResources(); if (resources != null)
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);
PDDocument pdf = new PDDocument(); // A5 page in landscape format PDPage page = new PDPage(PDRectangle.A5); page.setRotation(90); pdf.addPage(page); try (PDPageContentStream content = new PDPageContentStream(pdf, page)) { int fontSize = 36; // Put the text at the page's center, no offset Point2D.Float center = new Point2D.Float(0, 0); addCenteredText("PDFBox", PDType1Font.HELVETICA_BOLD, fontSize, content, page, center); // Put the text centered at the lower end of the page Point2D.Float lowerCenter = new Point2D.Float(0, -165); addCenteredText("Hi there!", PDType1Font.HELVETICA, fontSize, content, page, lowerCenter); } catch (IOException e) { LOG.warn("Exception while creating content", e); }
page.setRotation(90); doc.addPage(page); PDRectangle pageSize = page.getMediaBox();
importedPage.setRotation( ((PDPage)pages.get(j)).findRotation() );
page.setRotation(0); page.setRotation(rotation);
page.setRotation(0); AngleCollector angleCollector = new AngleCollector(); angleCollector.setStartPage(p); page.setRotation(rotation);
importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
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; }