@Override public PDRectangle getBBox() { return getCropBox(); }
/** * Initializes the stream engine for the given page. */ private void initPage(PDPage page) { if (page == null) { throw new IllegalArgumentException("Page cannot be null"); } currentPage = page; graphicsStack.clear(); graphicsStack.push(new PDGraphicsState(page.getCropBox())); textMatrix = null; textLineMatrix = null; resources = null; initialMatrix = page.getMatrix(); }
protected ObjectExtractorStreamEngine(PDPage page) { super(page); this.log = LoggerFactory.getLogger(ObjectExtractorStreamEngine.class); this.rulings = new ArrayList<>(); this.pageTransform = null; // calculate page transform PDRectangle cb = this.getPage().getCropBox(); int rotation = this.getPage().getRotation(); this.pageTransform = new AffineTransform(); if (Math.abs(rotation) == 90 || Math.abs(rotation) == 270) { this.pageTransform = AffineTransform.getRotateInstance(rotation * (Math.PI / 180.0), 0, 0); this.pageTransform.concatenate(AffineTransform.getScaleInstance(1, -1)); } else { this.pageTransform.concatenate(AffineTransform.getTranslateInstance(0, cb.getHeight())); this.pageTransform.concatenate(AffineTransform.getScaleInstance(1, -1)); } this.pageTransform.translate(-cb.getLowerLeftX(), -cb.getLowerLeftY()); }
private void transform(Graphics2D graphics, PDPage page, float scale) { graphics.scale(scale, scale); int rotationAngle = page.getRotation(); PDRectangle cropBox = page.getCropBox(); if (rotationAngle != 0) { float translateX = 0; float translateY = 0; switch (rotationAngle) { case 90: translateX = cropBox.getHeight(); break; case 270: translateY = cropBox.getWidth(); break; case 180: translateX = cropBox.getWidth(); translateY = cropBox.getHeight(); break; default: break; } graphics.translate(translateX, translateY); graphics.rotate((float) Math.toRadians(rotationAngle)); } }
private void transform(Graphics2D graphics, PDPage page, float scaleX, float scaleY) { graphics.scale(scaleX, scaleY); // TODO should we be passing the scale to PageDrawer rather than messing with Graphics? int rotationAngle = page.getRotation(); PDRectangle cropBox = page.getCropBox(); if (rotationAngle != 0) { float translateX = 0; float translateY = 0; switch (rotationAngle) { case 90: translateX = cropBox.getHeight(); break; case 270: translateY = cropBox.getWidth(); break; case 180: translateX = cropBox.getWidth(); translateY = cropBox.getHeight(); break; default: break; } graphics.translate(translateX, translateY); graphics.rotate(Math.toRadians(rotationAngle)); } }
public void mouseMoved(MouseEvent e) float height = page.getCropBox().getHeight(); float width = page.getCropBox().getWidth(); float offsetX = page.getCropBox().getLowerLeftX(); float offsetY = page.getCropBox().getLowerLeftY(); float zoomScale = zoomMenu.getPageZoomScale(); float x = e.getX() / zoomScale * (float) defaultTransform.getScaleX();
protected Page extractPage(Integer pageNumber) throws IOException { if (pageNumber > this.pdfDocument.getNumberOfPages() || pageNumber < 1) { throw new java.lang.IndexOutOfBoundsException( "Page number does not exist"); } PDPage p = this.pdfDocument.getPage(pageNumber - 1); ObjectExtractorStreamEngine se = new ObjectExtractorStreamEngine(p); se.processPage(p); TextStripper pdfTextStripper = new TextStripper(this.pdfDocument, pageNumber); pdfTextStripper.process(); Utils.sort(pdfTextStripper.textElements, Rectangle.ILL_DEFINED_ORDER); float w, h; int pageRotation = p.getRotation(); if (Math.abs(pageRotation) == 90 || Math.abs(pageRotation) == 270) { w = p.getCropBox().getHeight(); h = p.getCropBox().getWidth(); } else { w = p.getCropBox().getWidth(); h = p.getCropBox().getHeight(); } return new Page(0, 0, w, h, pageRotation, pageNumber, p, pdfTextStripper.textElements, se.rulings, pdfTextStripper.minCharWidth, pdfTextStripper.minCharHeight, pdfTextStripper.spatialIndex); }
/** * A rectangle, expressed in default user space units, defining the intended dimensions of the * finished page after trimming. The default is the CropBox. * * @return The TrimBox attribute. */ public PDRectangle getTrimBox() { COSBase base = page.getDictionaryObject(COSName.TRIM_BOX); if (base instanceof COSArray) { return clipToMediaBox(new PDRectangle((COSArray) base)); } else { return getCropBox(); } }
/** * A rectangle, expressed in default user space units, defining the region to which the contents * of the page should be clipped when output in a production environment. The default is the * CropBox. * * @return The BleedBox attribute. */ public PDRectangle getBleedBox() { COSBase base = page.getDictionaryObject(COSName.BLEED_BOX); if (base instanceof COSArray) { return clipToMediaBox(new PDRectangle((COSArray) base)); } else { return getCropBox(); } }
/** * A rectangle, expressed in default user space units, defining the extent of the page's * meaningful content (including potential white space) as intended by the page's creator The * default is the CropBox. * * @return The ArtBox attribute. */ public PDRectangle getArtBox() { COSBase base = page.getDictionaryObject(COSName.ART_BOX); if (base instanceof COSArray) { return clipToMediaBox(new PDRectangle((COSArray) base)); } else { return getCropBox(); } }
public void stripPage(PDDocument document, PDPage page, int pageIndex, float scale) throws IOException PDRectangle cropBox = page.getCropBox(); this.flip = new AffineTransform(); flip.translate(0, cropBox.getHeight());
/** * This will initialize and process the contents of the stream. * * @param page the page to process * @throws java.io.IOException if there is an error accessing the stream. */ @Override public void processPage(PDPage page) throws IOException { this.pageRotation = page.getRotation(); this.pageSize = page.getCropBox(); if (Float.compare(pageSize.getLowerLeftX(), 0) == 0 && Float.compare(pageSize.getLowerLeftY(), 0) == 0) { translateMatrix = null; } else { // translation matrix for cropbox translateMatrix = Matrix.getTranslateInstance(-pageSize.getLowerLeftX(), -pageSize.getLowerLeftY()); } super.processPage(page); }
/** * Renders a given page to an AWT Graphics2D instance. * * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @param scaleX the scale to draw the page at for the x-axis * @param scaleY the scale to draw the page at for the y-axis * @param destination controlling visibility of optional content groups * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scaleX, float scaleY, RenderDestination destination) throws IOException { PDPage page = document.getPage(pageIndex); // TODO need width/wight calculations? should these be in PageDrawer? transform(graphics, page, scaleX, scaleY); PDRectangle cropBox = page.getCropBox(); graphics.clearRect(0, 0, (int) cropBox.getWidth(), (int) cropBox.getHeight()); // the end-user may provide a custom PageDrawer RenderingHints actualRenderingHints = renderingHints == null ? createDefaultRenderingHints(graphics) : renderingHints; PageDrawerParameters parameters = new PageDrawerParameters(this, page, subsamplingAllowed, destination, actualRenderingHints); PageDrawer drawer = createPageDrawer(parameters); drawer.drawPage(graphics, cropBox); }
/** * This will find the CropBox with rotation applied, for this page by looking up the hierarchy * until it finds them. * * @return The CropBox at this level in the hierarchy. */ static PDRectangle getRotatedCropBox(PDPage page) { PDRectangle cropBox = page.getCropBox(); int rotationAngle = page.getRotation(); if (rotationAngle == 90 || rotationAngle == 270) { return new PDRectangle(cropBox.getLowerLeftY(), cropBox.getLowerLeftX(), cropBox.getHeight(), cropBox.getWidth()); } else { return cropBox; } }
PDRectangle cropBox = page.getCropBox(); if (Float.compare(cropBox.getLowerLeftX(), 0) != 0 || Float.compare(cropBox.getLowerLeftY(), 0) != 0)
final int cols = content[0].length; final float rowHeight = 20f; final float tableWidth = page.getCropBox().getWidth() - margin - margin; final float tableHeight = rowHeight * rows; final float colWidth = tableWidth/(float)cols;
importedPage.setContents(dest); addPage(importedPage); importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation());
float height = (float) humanRect.getHeight(); PDPage page = doc.getPage(0); PDRectangle pageRect = page.getCropBox(); PDRectangle rect = new PDRectangle();
PDRectangle cropBox = targetPage.getCropBox(); if ((cropBox.getLowerLeftX() < 0 || cropBox.getLowerLeftY() < 0) && transform.isIdentity())
imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources());