/** * Gets page size, defined by media box object. This method doesn't take page rotation into account. * * @return {@link Rectangle} that specify page size. */ public Rectangle getPageSize() { return getMediaBox(); }
/** * Gets the {@link Rectangle} specified by page's CropBox, that defines the visible region of default user space. * When the page is displayed or printed, its contents shall be clipped (cropped) to this rectangle * and then shall be imposed on the output medium in some implementation-defined manner. * * @return the {@link Rectangle} object specified by pages's CropBox, expressed in default user space units. * MediaBox by default. */ public Rectangle getCropBox() { PdfArray cropBox = getPdfObject().getAsArray(PdfName.CropBox); if (cropBox == null) { cropBox = (PdfArray) getInheritedValue(PdfName.CropBox, PdfObject.ARRAY); if (cropBox == null) { return getMediaBox(); } } return cropBox.toRectangle(); }
private void copyInheritedProperties(PdfPage copyPdfPage, PdfDocument pdfDocument) { if (copyPdfPage.getPdfObject().get(PdfName.Resources) == null) { PdfObject copyResource = pdfDocument.getWriter().copyObject(getResources().getPdfObject(), pdfDocument, false); copyPdfPage.getPdfObject().put(PdfName.Resources, copyResource); } if (copyPdfPage.getPdfObject().get(PdfName.MediaBox) == null) { //media box shall be in any case copyPdfPage.setMediaBox(getMediaBox()); } if (copyPdfPage.getPdfObject().get(PdfName.CropBox) == null) { //original pdfObject don't have CropBox, otherwise copyPdfPage will contain it PdfArray cropBox = (PdfArray) getInheritedValue(PdfName.CropBox, PdfObject.ARRAY); //crop box is optional, we shall not set default value. if (cropBox != null) { copyPdfPage.put(PdfName.CropBox, cropBox.copyTo(pdfDocument)); } } if (copyPdfPage.getPdfObject().get(PdfName.Rotate) == null) { //original pdfObject don't have Rotate, otherwise copyPdfPage will contain it PdfNumber rotate = (PdfNumber) getInheritedValue(PdfName.Rotate, PdfObject.NUMBER); //rotate is optional, we shall not set default value. if (rotate != null) { copyPdfPage.put(PdfName.Rotate, rotate.copyTo(pdfDocument)); } } }