/** * Gets page size, considering page rotation. * * @return {@link Rectangle} that specify size of rotated page. */ public Rectangle getPageSizeWithRotation() { PageSize rect = new PageSize(getPageSize()); int rotation = getRotation(); while (rotation > 0) { rect = rect.rotate(); rotation -= 90; } return rect; }
/** * Convenience method for fast PdfCanvas creation by a certain page. * * @param page page to create canvas from. */ public PdfCanvas(PdfPage page) { this(page, (page.getDocument().getReader() != null && page.getDocument().getWriter() != null && page.getContentStreamCount() > 0 && page.getLastContentStream().getLength() > 0) || (page.getRotation() != 0 && page.isIgnorePageRotationForContent())); }
private void applyRotation(PdfPage page) { Rectangle rectangle = page.getPageSizeWithRotation(); int rotation = page.getRotation(); switch (rotation) { case 90: concatMatrix(0, 1, -1, 0, rectangle.getTop(), 0); break; case 180: concatMatrix(-1, 0, 0, -1, rectangle.getRight(), rectangle.getTop()); break; case 270: concatMatrix(0, -1, 1, 0, 0, rectangle.getRight()); break; } }
/** * Convenience method for fast PdfCanvas creation by a certain page. * * @param page page to create canvas from. * @param wrapOldContent true to wrap all old content streams into q/Q operators so that the state of old * content streams would not affect the new one */ public PdfCanvas(PdfPage page, boolean wrapOldContent) { this(getPageStream(page), page.getResources(), page.getDocument()); if (wrapOldContent) { // Wrap old content in q/Q in order not to get unexpected results because of the CTM page.newContentStreamBefore().getOutputStream().writeBytes(ByteUtils.getIsoBytes("q\n")); contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("Q\n")); } if (page.getRotation() != 0 && page.isIgnorePageRotationForContent() && (wrapOldContent || !page.isPageRotationInverseMatrixWritten())) { applyRotation(page); page.setPageRotationInverseMatrixWritten(); } }
int rotation = document.getPage(page).getRotation(); Rectangle rotated = new Rectangle(rect);
int rotation = document.getPage(page).getRotation(); Rectangle rotated = new Rectangle(rect);
pageRotation = page.getRotation();
pageRotation = page.getRotation();