Example usage for com.lowagie.text ExceptionConverter ExceptionConverter

List of usage examples for com.lowagie.text ExceptionConverter ExceptionConverter

Introduction

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

Prototype

public ExceptionConverter(Exception ex) 

Source Link

Document

Construct a RuntimeException based on another Exception

Usage

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

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {/*from  w w  w. j a  v  a 2  s. c  om*/

        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:questions.forms.FormWithTooltips.java

/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
 *      com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 *//*from  w  ww. j a va2s  .  com*/
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) {
    kid.setWidget(new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding),
            rect.getTop(padding)), PdfAnnotation.HIGHLIGHT_INVERT);
    kid.setUserName(tooltip);
    try {
        parent.addKid(kid);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:questions.tables.AddTableAsHeaderFooter.java

public void onOpenDocument(PdfWriter writer, Document document) {
    try {/*from  w w  w. j a v a 2 s.c om*/
        // initializations
        tpl = writer.getDirectContent().createTemplate(150, 18);
        Rectangle rect = new Rectangle(0, 0, 150, 18);
        rect.setBackgroundColor(Color.GRAY);
        tpl.setBoundingBox(rect);
        tpl.rectangle(rect);
        helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
        // header
        headerTable = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph("Header Text"));
        headerTable.addCell(cell);
        headerTable.setTotalWidth(document.right() - document.left());
        headerTable.setLockedWidth(true);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:questions.tables.AddTableAsHeaderFooter.java

public void onEndPage(PdfWriter writer, Document document) {
    try {//ww  w.  j  av a 2 s. c  om
        // Header
        headerTable.writeSelectedRows(0, -1, document.leftMargin(),
                document.top() + headerTable.getTotalHeight(), writer.getDirectContent());
        // Footer
        PdfPTable footerTable = new PdfPTable(2);
        PdfPCell cell1 = new PdfPCell(new Phrase("page " + writer.getPageNumber()));
        footerTable.addCell(cell1);
        PdfPCell cell2 = new PdfPCell(Image.getInstance(tpl));
        footerTable.addCell(cell2);
        footerTable.setTotalWidth(document.right() - document.left());
        footerTable.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}