/** Gets the page size without taking rotation into account. This * is the value of the /MediaBox key. * @param index the page number. The first page is 1 * @return the page size */ public Rectangle getPageSize(final int index) { return getPageSize(pageRefs.getPageNRelease(index)); }
/** Gets the page size without taking rotation into account. This * is the value of the /MediaBox key. * @param index the page number. The first page is 1 * @return the page size */ public Rectangle getPageSize(final int index) { return getPageSize(pageRefs.getPageNRelease(index)); }
/** * Gets the rotated page from a page dictionary. * @param page the page dictionary * @return the rotated page */ public Rectangle getPageSizeWithRotation(final PdfDictionary page) { Rectangle rect = getPageSize(page); int rotation = getPageRotation(page); while (rotation > 0) { rect = rect.rotate(); rotation -= 90; } return rect; }
/** * Gets the rotated page from a page dictionary. * @param page the page dictionary * @return the rotated page */ public Rectangle getPageSizeWithRotation(final PdfDictionary page) { Rectangle rect = getPageSize(page); int rotation = getPageRotation(page); while (rotation > 0) { rect = rect.rotate(); rotation -= 90; } return rect; }
PdfReader insert = new PdfReader(INSERT); PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(DEST)); stamper.insertPage(4, insert.getPageSize(1)); PdfContentByte cb = stamper.getOverContent(4); cb.addTemplate(stamper.getImportedPage(insert, 1), 0, 0); ... stamper.close();
PdfReader reader = new PdfReader(main_file); PdfReader reader2 = new PdfReader(to_be_inserted); // Create a stamper PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); // Create an imported page to be inserted PdfImportedPage page = stamper.getImportedPage(reader2, 1); stamper.insertPage(p, reader2.getPageSize(1)); stamper.getUnderContent(i).addTemplate(page, 0, 0); // Close the stamper and the readers stamper.close(); reader.close(); reader2.close();
/** Gets the crop box without taking rotation into account. This * is the value of the /CropBox key. The crop box is the part * of the document to be displayed or printed. It usually is the same * as the media box but may be smaller. If the page doesn't have a crop * box the page size will be returned. * @param index the page number. The first page is 1 * @return the crop box */ public Rectangle getCropBox(final int index) { PdfDictionary page = pageRefs.getPageNRelease(index); PdfArray cropBox = (PdfArray)getPdfObjectRelease(page.get(PdfName.CROPBOX)); if (cropBox == null) return getPageSize(page); return getNormalizedRectangle(cropBox); }
/** Gets the crop box without taking rotation into account. This * is the value of the /CropBox key. The crop box is the part * of the document to be displayed or printed. It usually is the same * as the media box but may be smaller. If the page doesn't have a crop * box the page size will be returned. * @param index the page number. The first page is 1 * @return the crop box */ public Rectangle getCropBox(final int index) { PdfDictionary page = pageRefs.getPageNRelease(index); PdfArray cropBox = (PdfArray)getPdfObjectRelease(page.get(PdfName.CROPBOX)); if (cropBox == null) return getPageSize(page); return getNormalizedRectangle(cropBox); }
PdfReader reader = new PdfReader(src); // We assume that there's a single large picture on the first page PdfDictionary page = reader.getPageN(1); PdfDictionary resources = page.getAsDict(PdfName.RESOURCES); PdfDictionary xobjects = resources.getAsDict(PdfName.XOBJECT); PdfName imgName = xobjects.getKeys().iterator().next(); Image img = Image.getInstance((PRIndirectReference)xobjects.getAsIndirectObject(imgName)); img.setAbsolutePosition(0, 0); img.scaleAbsolute(reader.getPageSize(1)); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.getOverContent(1).addImage(img); stamper.close(); reader.close();
public void addWaterMark(PdfStamper stamper, int pageNumber, Watermark watermark){ List<WatermarkField> watermarkFields = watermark.getWatermarkFieldAsReference(); PdfReader reader = stamper.getReader(); Rectangle pageSize = reader.getPageSize(1); BaseFont font = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); PdfPatternPainter painter = stamper.getOverContent(1).createPattern(pageSize.getWidth(), pageSize.getHeight()); painter.setColorStroke(new BaseColor(192, 192, 192)); painter.setLineDash(0.4f, 0.4f, 0.2f); painter.beginText(); painter.setTextMatrix(AffineTransform.getTranslateInstance(0, 50)); for (WatermarkField watermarkField : watermarkFields) { painter.setFontAndSize(font, watermarkField.getFontSize()); painter.showTextAlignedKerned(Element.ALIGN_MIDDLE, watermarkField.getText(), watermarkField.getXDirection(), watermarkField.getYDirection(), watermarkField.getRotation()); } painter.endText(); PdfGState state = new PdfGState(); state.setFillOpacity(0.2f); PdfContentByte overContent = stamper.getOverContent(pageNumber); overContent.setGState(state); overContent.setColorFill(new PatternColor(painter)); overContent.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight()); overContent.fill(); }
PdfImportedPage(PdfReaderInstance readerInstance, PdfWriter writer, int pageNumber) { this.readerInstance = readerInstance; this.pageNumber = pageNumber; this.writer = writer; rotation = readerInstance.getReader().getPageRotation(pageNumber); bBox = readerInstance.getReader().getPageSize(pageNumber); setMatrix(1, 0, 0, 1, -bBox.getLeft(), -bBox.getBottom()); type = TYPE_IMPORTED; }
PdfImportedPage(PdfReaderInstance readerInstance, PdfWriter writer, int pageNumber) { this.readerInstance = readerInstance; this.pageNumber = pageNumber; this.writer = writer; rotation = readerInstance.getReader().getPageRotation(pageNumber); bBox = readerInstance.getReader().getPageSize(pageNumber); setMatrix(1, 0, 0, 1, -bBox.getLeft(), -bBox.getBottom()); type = TYPE_IMPORTED; }
Rectangle pageSize = reader.getPageSize(1);
Rectangle pageSize = reader.getPageSize(1); PdfStamper stamper = new PdfStamper(reader, out); while (true) {
fp.page = page; if (rotation != 0) { Rectangle pageSize = reader.getPageSize(page); switch (rotation) { case 270:
fp.page = page; if (rotation != 0) { Rectangle pageSize = reader.getPageSize(page); switch (rotation) { case 270: