Example usage for com.lowagie.text Document getPageNumber

List of usage examples for com.lowagie.text Document getPageNumber

Introduction

In this page you can find the example usage for com.lowagie.text Document getPageNumber.

Prototype


public int getPageNumber() 

Source Link

Document

Returns the current page number.

Usage

From source file:org.cyberoam.iview.charts.Chart.java

License:Open Source License

/**
 * This Event handler Method adds Header and Footer in PDF File
 */// ww  w .  j  a  va2 s. co m
public void onEndPage(PdfWriter writer, Document document) {
    try {
        if (document.getPageNumber() > 1) {
            String seperator = System.getProperty("file.separator");
            //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator;
            String path = InitServlet.contextPath + seperator + "images" + seperator;
            Image imgHead = Image.getInstance(path + "iViewPDFHeader.JPG");
            Image imgFoot = Image.getInstance(path + "iViewPDFFooter.JPG");
            Rectangle page = document.getPageSize();

            PdfPTable head = new PdfPTable(1);
            head.addCell(imgHead);
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin() - 10,
                    page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

            PdfPTable foot = new PdfPTable(1);
            foot.addCell(imgFoot);
            foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin() - 10, document.bottomMargin() + 24,
                    writer.getDirectContent());
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:org.opentestsystem.delivery.testreg.rest.view.PdfReportPageEventHelper.java

License:Open Source License

@Override
public void onEndPage(final PdfWriter writer, final Document document) {
    PdfContentByte cb = writer.getDirectContent();
    if (document.getPageNumber() == 1) {
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(""),
                (document.right() - document.left()) / 2 + document.leftMargin(), document.top() - 5, 0f);
    }/*from  w w  w.  j a  va  2  s  .  co m*/
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(""), document.left(), document.bottom() - 15,
            0f);

    int pageN = writer.getPageNumber();
    String text = "Page " + pageN + " of ";
    cb.beginText();
    cb.setFontAndSize(helv, 11);
    cb.setTextMatrix(document.right() - document.rightMargin() - 10, document.bottom() - 15);
    cb.showText(text);
    cb.endText();
    cb.addTemplate(template, document.right(), document.bottom() - 15);

}

From source file:org.sonar.report.pdf.Toc.java

License:Open Source License

@Override
public void onChapter(PdfWriter writer, Document document, float position, Paragraph title) {
    // toc.add(new Paragraph(title.getContent() + " page " + document.getPageNumber()));
    content.getDefaultCell().setBorderColorBottom(Color.LIGHT_GRAY);
    content.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
    content.getDefaultCell().setUseBorderPadding(true);
    content.addCell(new Phrase(title.getContent(), new Font(Font.HELVETICA, 11)));
    content.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
    content.addCell(new Phrase("Page " + document.getPageNumber(), new Font(Font.HELVETICA, 11)));
    content.getDefaultCell().setBorderColorBottom(Color.WHITE);
    content.getDefaultCell().setUseBorderPadding(false);
}

From source file:org.sonarqube.report.extendedpdf.ExtendedToc.java

License:Open Source License

@Override
public void onChapter(PdfWriter writer, Document document, float position, Paragraph title) {
    content.getDefaultCell().setBorderColorBottom(Color.LIGHT_GRAY);
    content.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
    content.getDefaultCell().setUseBorderPadding(true);
    content.addCell(new Phrase(title.getContent(), new Font(Font.HELVETICA, 11)));
    content.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
    content.addCell(new Phrase("Page " + document.getPageNumber(), new Font(Font.HELVETICA, 11)));
    content.getDefaultCell().setBorderColorBottom(Color.WHITE);
    content.getDefaultCell().setUseBorderPadding(false);
}

From source file:org.unitime.timetable.util.PdfEventHandler.java

License:Open Source License

/**
 * Print footer string on each page//from  w ww .  j a  v  a  2s  .  co m
 * @param writer
 * @param document
 */
public void onEndPage(PdfWriter writer, Document document) {

    if (getDateTime() == null) {
        setDateTime(new Date());
    }

    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    cb.setFontAndSize(getBaseFont(), getFontSize());
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), document.left(), 20,
            0);
    cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), document.right(),
            20, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
            (document.left() + document.right()) / 2, 20, 0);
    cb.endText();

    return;
}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {// w w w  .  ja v a  2  s  .  com

        Rectangle page = document.getPageSize();
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        int pageNum = document.getPageNumber();
        float width = page.getWidth();
        float height = page.getHeight();

        //add patient name header for every page but the first.
        if (pageNum > 1) {
            cb.beginText();
            cb.setFontAndSize(bf, 8);
            cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, handler.getPatientName(), 575, height - 30, 0);
            cb.endText();

        }

        //add footer for every page
        cb.beginText();
        cb.setFontAndSize(bf, 8);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "-" + pageNum + "-", width / 2, 30, 0);
        cb.endText();

        // add promotext as footer if it is enabled
        if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) {
            cb.beginText();
            cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED),
                    6);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
                    OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), width / 2, 19, 0);
            cb.endText();
        }

        // throw any exceptions
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:storemanagment.FooterOnly.java

/**
 *
 * @param writer//  w  w w. j  a  va 2  s . c o  m
 * @param document
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase("Officer In Charge : " + officerInCharge), 110, 30, 0);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase("Sign : _________________       " + document.getPageNumber()), 550, 30, 0);
}