Search in sources :

Example 6 with ExceptionConverter

use of com.itextpdf.text.ExceptionConverter in project trainning by fernandotomasio.

the class TCAPageFooter method onEndPage.

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        table.setWidths(new int[] { 20, 80, 20 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        String anexo = "";
        if (writer.getPageNumber() >= 8 && writer.getPageNumber() <= 11) {
            anexo = "Anexo A - Relação de cursos previstos";
        } else if (writer.getPageNumber() >= 8 && writer.getPageNumber() <= 224) {
            anexo = "Anexo B - Folha de Rosto dos Cursos Previstos";
        } else if (writer.getPageNumber() == 225) {
            anexo = "Anexo C - Modelo de Ficha de Indicação CNS014";
        }
        if (writer.getPageNumber() % 2 != 0) {
            table.addCell(new Phrase(header, new Font(Font.FontFamily.HELVETICA, 10)));
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell anexoCell = new PdfPCell(new Phrase(String.format(anexo, writer.getPageNumber()), new Font(Font.FontFamily.HELVETICA, 10)));
            anexoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            anexoCell.setBorder(Rectangle.NO_BORDER);
            table.addCell(anexo);
            table.addCell(new Phrase(String.format("%d", writer.getPageNumber()), new Font(Font.FontFamily.HELVETICA, 10)));
        } else {
            table.addCell(new Phrase(String.format("%d", writer.getPageNumber()), new Font(Font.FontFamily.HELVETICA, 10)));
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            PdfPCell anexoCell = new PdfPCell(new Phrase(String.format(anexo, writer.getPageNumber()), new Font(Font.FontFamily.HELVETICA, 10)));
            anexoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            anexoCell.setBorder(Rectangle.NO_BORDER);
            table.addCell(anexo);
            table.addCell(new Phrase(header, new Font(Font.FontFamily.HELVETICA, 10)));
        // table.getDefaultCell().setHorizontalAlignment(
        // Element.ALIGN_RIGHT);
        }
        PdfPCell cell = new PdfPCell(Image.getInstance(total));
        cell.setBorder(Rectangle.NO_BORDER);
        // table.addCell(cell);
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}
Also used : ExceptionConverter(com.itextpdf.text.ExceptionConverter) PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) DocumentException(com.itextpdf.text.DocumentException) Phrase(com.itextpdf.text.Phrase) Font(com.itextpdf.text.Font)

Aggregations

DocumentException (com.itextpdf.text.DocumentException)6 ExceptionConverter (com.itextpdf.text.ExceptionConverter)6 PdfPTable (com.itextpdf.text.pdf.PdfPTable)6 PdfPCell (com.itextpdf.text.pdf.PdfPCell)4 Font (com.itextpdf.text.Font)2 Phrase (com.itextpdf.text.Phrase)2