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);
}
}
Aggregations