Example usage for com.itextpdf.text.pdf PdfCopy createPageStamp

List of usage examples for com.itextpdf.text.pdf PdfCopy createPageStamp

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfCopy createPageStamp.

Prototype

public PageStamp createPageStamp(PdfImportedPage iPage) 

Source Link

Document

Create a page stamp.

Usage

From source file:be.rheynaerde.pufmanager.gui.workers.ExportFullPdfWorker.java

License:Open Source License

private void addPdfToDocument(ByteArrayOutputStream baos, PdfCopy copy, String stampText)
        throws IOException, BadPdfFormatException {
    PdfReader reader = new PdfReader(new ByteArrayInputStream(baos.toByteArray()));
    int n = reader.getNumberOfPages();
    for (int page = 1; page <= n; page++) {
        PdfImportedPage importedPage = copy.getImportedPage(reader, page);
        PdfCopy.PageStamp stamp = copy.createPageStamp(importedPage);
        Rectangle rectangle = importedPage.getBoundingBox();
        ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(stampText),
                rectangle.getRight() - 20f, rectangle.getTop() - 20f, 0);
        stamp.alterContents();// ww w.  j av a2 s .  c o m
        copy.addPage(importedPage);
    }
}

From source file:fenix.planner.pdf.PDFGenerator.java

License:Open Source License

private void addPageNumbers(PdfReader reader, PdfCopy copy) {
    int pageCount = reader.getNumberOfPages();
    PdfImportedPage page;//  w  ww  . ja va 2  s  .c o  m
    PdfCopy.PageStamp stamp;

    for (int i = 1; i <= pageCount; ++i) {
        Rectangle rect = reader.getBoxSize(i, "art");
        page = copy.getImportedPage(reader, i);
        stamp = copy.createPageStamp(page);
        // add page numbers
        ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT,
                new Phrase(String.format("%d / %d", i, pageCount), footerFont), rect.getRight(),
                rect.getBottom() + 5, 0);
        try {
            stamp.alterContents();
            copy.addPage(page);
        } catch (BadPdfFormatException | IOException ex) {
            throw new PDFGenerationException("Error adding page number to page " + i, ex);
        }
    }
}