/** * Gets the {@link Rectangle} object specified by page's ArtBox, that define the extent of the page’s * meaningful content (including potential white space) as intended by the page’s creator. * * @return the {@link Rectangle} object specified by page's ArtBox, expressed in default user space units. * CropBox by default. */ public Rectangle getArtBox() { Rectangle artBox = getPdfObject().getAsRectangle(PdfName.ArtBox); return artBox == null ? getCropBox() : artBox; }
/** * Gets the {@link Rectangle} object specified by page's BleedBox, that define the region to which the * contents of the page shall be clipped when output in a production environment. * * @return the {@link Rectangle} object specified by page's BleedBox, expressed in default user space units. * CropBox by default. */ public Rectangle getBleedBox() { Rectangle bleedBox = getPdfObject().getAsRectangle(PdfName.BleedBox); return bleedBox == null ? getCropBox() : bleedBox; }
/** * Gets the {@link Rectangle} object specified by page's TrimBox object, * that define the intended dimensions of the finished page after trimming. * * @return the {@link Rectangle} object specified by page's TrimBox, expressed in default user space units. * CropBox by default. */ public Rectangle getTrimBox() { Rectangle trimBox = getPdfObject().getAsRectangle(PdfName.TrimBox); return trimBox == null ? getCropBox() : trimBox; }
private void initClippingPath(PdfPage page) { Path clippingPath = new Path(); clippingPath.rectangle(page.getCropBox()); getGraphicsState().setClippingPath(clippingPath); }
/** * Copies page as FormXObject to the specified document. * * @param toDocument a document to copy to. * @return copied {@link PdfFormXObject} object. */ public PdfFormXObject copyAsFormXObject(PdfDocument toDocument) throws IOException { PdfFormXObject xObject = new PdfFormXObject(getCropBox()); List<PdfName> excludedKeys = new ArrayList<>(Arrays.asList(PdfName.MediaBox, PdfName.CropBox, PdfName.Contents) ); excludedKeys.addAll(this.excludedKeys); PdfDictionary dictionary = getPdfObject().copyTo(toDocument, excludedKeys, true); xObject.getPdfObject().getOutputStream().write(getContentBytes()); xObject.getPdfObject().mergeDifferent(dictionary); //Copy inherited resources if (!xObject.getPdfObject().containsKey(PdfName.Resources)) { PdfObject copyResource = getResources().getPdfObject().copyTo(toDocument, true); xObject.getPdfObject().put(PdfName.Resources, copyResource); } return xObject; }
/** * Creates form XObject from page content. * The page shall be from the document, to which FormXObject will be added. * * @param page an instance of {@link PdfPage} */ public PdfFormXObject(PdfPage page) { this(page.getCropBox()); getPdfObject().getOutputStream().writeBytes(page.getContentBytes()); resources = new PdfResources((PdfDictionary) page.getResources().getPdfObject().clone()); getPdfObject().put(PdfName.Resources, resources.getPdfObject()); }