// Evento cuando que se ejecuta al terminar una página @Override public void onEndPage(PdfWriter writer, Document document) { // Creamos una tabla de dos culumnas PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_CENTER); try { // Establecemos las medidas de la tabla table.setWidths(new int[] {24, 10}); table.setTotalWidth(100); // Establecemos la altura de la celda table.getDefaultCell().setFixedHeight(20); // Quitamos el borde table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // Alineamos el contenido a la derecha table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); // Escribimos el primer texto // en la primera celda table.addCell(String.format("Página %d de ", writer.getCurrentPageNumber())); // Obtenemos el template total // y lo agregamos a la celda PdfPCell cell = new PdfPCell(Image.getInstance(total)); // quitamos el borde cell.setBorder(Rectangle.NO_BORDER); // lo agregamos a la tabla table.addCell(cell); table.writeSelectedRows(0, -1, 330, 40, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } }
private static void createInfospcoopTable(Section subCatPart, Infospcoop infospcoop) throws BadElementException { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Infospcoop")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); table.setHeaderRows(1); // riga 1 table.addCell(new Phrase("IdEgov")); table.addCell(new Phrase(infospcoop.getIdEgov())); // riga 2 table.addCell(new Phrase("Soggetto Erogatore")); table.addCell( new Phrase( infospcoop.getTipoSoggettoErogatore() + "/" + infospcoop.getSoggettoErogatore())); // riga 3 table.addCell(new Phrase("Soggetto Fruitore")); table.addCell( new Phrase(infospcoop.getTipoSoggettoFruitore() + "/" + infospcoop.getSoggettoFruitore())); // riga 4 table.addCell(new Phrase("Servizio")); table.addCell(new Phrase(infospcoop.getTipoServizio() + "/" + infospcoop.getServizio())); // riga 5 table.addCell(new Phrase("Azione")); table.addCell(new Phrase(infospcoop.getAzione())); subCatPart.add(table); }
/** * Creates an empty cell. * * @param colspan The column span of the cell. * @param height The height of the column. * @return A PdfCell. */ public static PdfPCell getEmptyCell(int colSpan, int height) { PdfPCell cell = new PdfPCell(); cell.setColspan(colSpan); cell.setBorder(0); cell.setMinimumHeight(height); return cell; }
public static PdfPCell resetPaddings( PdfPCell cell, float top, float bottom, float left, float right) { cell.setPaddingTop(top); cell.setPaddingBottom(bottom); cell.setPaddingLeft(left); cell.setPaddingRight(right); return cell; }
protected void addRow( final PdfPTable table, final boolean needsBorder, final Paragraph... elements) { for (final Paragraph element : elements) { final PdfPCell cell = new PdfPCell(element); // cell.setHorizontalAlignment(element.getAlignment()); cell.setVerticalAlignment(Element.ALIGN_TOP); if (!needsBorder) cell.setBorderWidth(0); table.addCell(cell); } }
/** * Creates a cell. * * @param text The text to include in the cell. * @param colspan The column span of the cell. * @param font The font of the cell text. * @param horizontalAlign The vertical alignment of the text in the cell. * @return A PdfCell. */ public static PdfPCell getCell(String text, int colspan, Font font, int horizontalAlign) { Paragraph paragraph = new Paragraph(text, font); PdfPCell cell = new PdfPCell(paragraph); cell.setColspan(colspan); cell.setBorder(0); cell.setMinimumHeight(15); cell.setHorizontalAlignment(horizontalAlign); return cell; }
/** * Create a PdfPTable based on this Table object. * * @return a PdfPTable object * @throws BadElementException */ public PdfPTable createPdfPTable() throws BadElementException { if (!convert2pdfptable) { throw new BadElementException( MessageLocalization.getComposedMessage("no.error.just.an.old.style.table")); } setAutoFillEmptyCells(true); complete(); PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setComplete(complete); if (isNotAddedYet()) pdfptable.setSkipFirstHeader(true); SimpleTable t_evt = new SimpleTable(); t_evt.cloneNonPositionParameters(this); t_evt.setCellspacing(cellspacing); pdfptable.setTableEvent(t_evt); pdfptable.setHeaderRows(lastHeaderRow + 1); pdfptable.setSplitLate(cellsFitPage); pdfptable.setKeepTogether(tableFitsPage); if (!Float.isNaN(offset)) { pdfptable.setSpacingBefore(offset); } pdfptable.setHorizontalAlignment(alignment); if (locked) { pdfptable.setTotalWidth(width); pdfptable.setLockedWidth(true); } else { pdfptable.setWidthPercentage(width); } Row row; for (Iterator iterator = iterator(); iterator.hasNext(); ) { row = (Row) iterator.next(); Element cell; PdfPCell pcell; for (int i = 0; i < row.getColumns(); i++) { if ((cell = (Element) row.getCell(i)) != null) { if (cell instanceof Table) { pcell = new PdfPCell(((Table) cell).createPdfPTable()); } else if (cell instanceof Cell) { pcell = ((Cell) cell).createPdfPCell(); pcell.setPadding(cellpadding + cellspacing / 2f); SimpleCell c_evt = new SimpleCell(SimpleCell.CELL); c_evt.cloneNonPositionParameters((Cell) cell); c_evt.setSpacing(cellspacing * 2f); pcell.setCellEvent(c_evt); } else { pcell = new PdfPCell(); } pdfptable.addCell(pcell); } } } return pdfptable; }
public PdfPCell printStrTopLine( String text, int colspan, int fontsize, boolean bold, boolean border, int align) { try { if (text == null) text = ""; Paragraph p = new Paragraph(); float padding = 3.0f; // set bold feature if (bold) { p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize, Font.BOLD))); padding = 3.0f; } else p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize))); PdfPCell cell = new PdfPCell(p); // set colspan feature cell.setColspan(colspan); // set alignment feature if (align == 0) cell.setHorizontalAlignment(cell.ALIGN_LEFT); else if (align == 1) cell.setHorizontalAlignment(cell.ALIGN_CENTER); else if (align == 2) cell.setHorizontalAlignment(cell.ALIGN_RIGHT); // set border feature cell.setBorder(cell.NO_BORDER); cell.setBorder(cell.TOP); cell.setPaddingBottom(padding); return cell; } catch (Exception e) { return null; } }
public PdfPCell printLine(int colspan) { try { Paragraph p = new Paragraph(); PdfPCell cell = new PdfPCell(p); cell.setColspan(colspan); // set alignment feature cell.setBorder(cell.NO_BORDER); cell.setBorder(cell.BOTTOM); return cell; } catch (Exception e) { return null; } }
/** * Método que dibuja el pie de la página. * * @param writer Creador de documentos. * @param document Documento del informe. */ private void drawFooter(PdfWriter writer, Document document) { try { PdfContentByte cb = writer.getDirectContent(); cb.saveState(); PdfPTable table = new PdfPTable(2); table.setTotalWidth(new float[] {70, document.right() - document.left() - 70}); table.setLockedWidth(true); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBorder(Rectangle.BOX); table.getDefaultCell().setBorderWidth(0.1F); table.getDefaultCell().setBorderColor(BORDER_COLOR); table.getDefaultCell().setBackgroundColor(BACKGROUND_COLOR); table.getDefaultCell().setFixedHeight(45); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); /* * Image logo = Image.getInstance(FOOTER_IMAGE_URL); * logo.setBorder(Rectangle.BOX); logo.setBorderWidth(0.1F); * logo.setBorderColor(BORDER_COLOR); table.addCell(logo); */ table.addCell(""); PdfPTable tableInfo = new PdfPTable(1); tableInfo.setTotalWidth(document.right() - document.left() - 75); tableInfo.setLockedWidth(true); tableInfo.setHorizontalAlignment(Element.ALIGN_CENTER); tableInfo.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableInfo.getDefaultCell().setFixedHeight(20); tableInfo.getDefaultCell().setPadding(5); tableInfo.addCell( new Phrase(new Chunk(DateUtils.EXTENDED_DATE_FORMATTER.format(new Date()), FOOTER_FONT))); PdfPCell tableInfoCell = new PdfPCell(tableInfo.getDefaultCell()); tableInfoCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableInfoCell.setVerticalAlignment(Element.ALIGN_BOTTOM); tableInfoCell.setPhrase(new Phrase(new Chunk(DIRECCION, FOOTER_ITALIC_FONT))); tableInfo.addCell(tableInfoCell); table.addCell(tableInfo); table.writeSelectedRows(0, -1, document.left(), document.bottom() - 5, cb); cb.restoreState(); } catch (Exception e) { throw new ExceptionConverter(e); } }
/** * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable with * relevant contents and set its logo image if there is a logoImage to be used. * * @param writer The PdfWriter for this document. * @param document The document. * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, * com.lowagie.text.Document) */ @Override public void onOpenDocument(PdfWriter writer, Document document) { LOG.debug("onOpenDocument() started."); try { float[] headerWidths = {0.20f, 0.60f, 0.20f}; headerTable = new PdfPTable(headerWidths); headerTable.setWidthPercentage(100); headerTable.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.getDefaultCell().setBorderWidth(0); headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); if (StringUtils.isNotBlank(logoImage)) { logo = Image.getInstance(logoImage); logo.scalePercent(3, 3); headerTable.addCell(new Phrase(new Chunk(logo, 0, 0))); } else { // if we don't use images headerTable.addCell(new Phrase(new Chunk(""))); } PdfPCell cell; cell = new PdfPCell(new Paragraph("REQUEST FOR QUOTATION\nTHIS IS NOT AN ORDER", ver_17_normal)); cell.setBorderWidth(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); Paragraph p = new Paragraph(); p.add(new Chunk("\n R.Q. Number: ", ver_8_bold)); p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal)); cell = new PdfPCell(p); cell.setBorderWidth(0); headerTable.addCell(cell); // initialization of the template tpl = writer.getDirectContent().createTemplate(100, 100); // initialization of the font helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); } catch (Exception e) { throw new ExceptionConverter(e); } }
public PdfPTable getAsPdfPTable() { PdfPTable tabla = new PdfPTable(getColsWidths()); tabla.setWidthPercentage(getWidthPercentaje()); List<FormTableRow> rows = getRows(); for (FormTableRow row : rows) { FormCell formCell = row.getNextCell(); while (formCell != null) { PdfPCell pdfPCell = null; if (formCell.containsImage()) { pdfPCell = new PdfPCell(formCell.getImage()); } else { Paragraph paragraph = new Paragraph(formCell.getFormattedValue(), getFont(formCell)); pdfPCell = new PdfPCell(paragraph); } pdfPCell.setColspan(formCell.getColSpan()); if (formCell.getHorizontalAlignment() != -1) { pdfPCell.setHorizontalAlignment(formCell.getHorizontalAlignment()); } else { FormColumnInfo formColumnInfo = columnsInfo[formCell.getColumn()]; pdfPCell.setHorizontalAlignment(formColumnInfo.getHorizontalAlignment()); } if (formCell.isPaintBorder() == null) { FormColumnInfo formColumnInfo = columnsInfo[formCell.getColumn()]; if (!formColumnInfo.isPaintBorder()) { pdfPCell.setBorder(Rectangle.NO_BORDER); } } else if (!formCell.isPaintBorder()) { pdfPCell.setBorder(Rectangle.NO_BORDER); } tabla.addCell(pdfPCell); formCell = row.getNextCell(); } } return tabla; }
private static void addComponyLogo(Document d, HttpServletRequest request) throws ConfigurationException, DocumentException { PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(50); PdfPCell cell = null; try { imgPath = com.krawler.esp.utils.ConfigReader.getinstance().get("platformURL") + "b/" + companySubDomain + "/images/store/?company=true"; Image img = Image.getInstance(imgPath); cell = new PdfPCell(img); } catch (Exception e) { cell = new PdfPCell(new Paragraph(companyName, fontBig)); } cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); d.add(table); }
protected void insertCell( PdfPTable table, String text, int align, int colspan, Font font, int border) { PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); cell.setHorizontalAlignment(align); cell.setColspan(colspan); cell.setBorder(border); cell.setBorderColor(borderColor); cell.setBackgroundColor(backgroundColor); if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(minimumCellHeight); } table.addCell(cell); }
public PdfPCell printStrBoldUnderline(String text, int colspan, int fontsize, int align) { try { Paragraph p = new Paragraph(); float padding = 3f; // set bold feature p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize, Font.BOLD))); PdfPCell cell = new PdfPCell(p); // set colspan feature cell.setColspan(colspan); // set alignment feature if (align == 0) cell.setHorizontalAlignment(cell.ALIGN_LEFT); else if (align == 1) cell.setHorizontalAlignment(cell.ALIGN_CENTER); else if (align == 2) cell.setHorizontalAlignment(cell.ALIGN_RIGHT); // set border feature cell.disableBorderSide(cell.LEFT); cell.disableBorderSide(cell.RIGHT); cell.disableBorderSide(cell.TOP); cell.setPaddingBottom(padding); return cell; } catch (Exception e) { return null; } }
private static void addTitleSubtitle(Document d) throws DocumentException, JSONException { java.awt.Color tColor = new Color(0, 0, 0); fontBold.setColor(tColor); fontRegular.setColor(tColor); PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd"); java.util.Date today = new java.util.Date(); table.setWidthPercentage(100); table.setSpacingBefore(6); // Report Title PdfPCell cell = new PdfPCell(new Paragraph("Project Summary", fontBold)); cell.setBorder(0); cell.setBorderWidth(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); // Sub-title(s) cell = new PdfPCell(new Paragraph("(on comparison with " + baseName + ")", fontRegular)); cell.setBorder(0); cell.setBorderWidth(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); // Separator line PdfPTable line = new PdfPTable(1); line.setWidthPercentage(100); PdfPCell cell1 = null; cell1 = new PdfPCell(new Paragraph("")); cell1.setBorder(PdfPCell.BOTTOM); line.addCell(cell1); d.add(table); d.add(line); }
@SuppressWarnings("deprecation") public PdfPTable render() { PdfPTable pdfpTable = new PdfPTable(getTable().getRow().getColumns().size()); pdfpTable.setSpacingBefore(3); Row row = getTable().getRow(); List<Column> columns = row.getColumns(); // build table headers for (Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) { Column column = iter.next(); PdfPCell cell = new PdfPCell(new Paragraph(column.getTitle(), getHeaderCellFont())); cell.setPadding(3.0f); cell.setBackgroundColor(getHeaderBackgroundColor()); pdfpTable.addCell(cell); } // build table body Collection<?> items = getCoreContext().getPageItems(); int rowcount = 0; for (Object item : items) { rowcount++; columns = row.getColumns(); for (Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) { Column column = iter.next(); String property = column.getProperty(); Object value = column.getCellRenderer().getCellEditor().getValue(item, property, rowcount); PdfPCell cell = new PdfPCell(new Paragraph(value == null ? "" : String.valueOf(value), getCellFont())); cell.setPadding(3.0f); if (isRowEven(rowcount)) { cell.setBackgroundColor(getEvenCellBackgroundColor()); } else { cell.setBackgroundColor(getOddCellBackgroundColor()); } pdfpTable.addCell(cell); } } return pdfpTable; }
private void generateHeaderTable(User c, PdfPTable headerTable) throws Exception { // Generic User Image // PdfPTable headerTable = new PdfPTable(3); Image userImage = Image.getInstance(c.getImageUrl(), null); userImage.setAlignment(Element.ALIGN_RIGHT); userImage.scalePercent(40); PdfPCell userImageCell = new PdfPCell(userImage, false); userImageCell.setBorder(0); headerTable.addCell(userImageCell); // Generic logo Image logoImage = Image.getInstance(c.getLogoUrl()); logoImage.setAlignment(Element.ALIGN_RIGHT); logoImage.scalePercent(30); PdfPCell logoImageCell = new PdfPCell(logoImage, false); logoImageCell.setBorder(0); headerTable.addCell(logoImageCell); // Generic Stamp Image Image stampImage = Image.getInstance(c.getStampUrl()); stampImage.setAlignment(Element.ALIGN_RIGHT); stampImage.scalePercent(30); PdfPCell stampImageCell = new PdfPCell(stampImage, false); stampImageCell.setBorder(0); headerTable.addCell(stampImageCell); // cell = PDFCellStyles.borderlessCell("Expense Form"); // headerTable.addCell(cell); if (c.getName() != null && c.getName() != "") { headerTable.addCell(PDFCellStyles.borderlessCell("")); headerTable.addCell(PDFCellStyles.borderlessCell("User Name")); headerTable.addCell(PDFCellStyles.borderlessCell(c.getName())); } if (c.getAddress() != null && c.getAddress() != "") { headerTable.addCell(PDFCellStyles.borderlessCell("")); headerTable.addCell(PDFCellStyles.borderlessCell("Company")); headerTable.addCell(PDFCellStyles.borderlessCell(c.getAddress())); } if (c.getPhone() != null && c.getPhone() != "") { headerTable.addCell(PDFCellStyles.borderlessCell("")); headerTable.addCell(PDFCellStyles.borderlessCell("Phone Number")); headerTable.addCell(PDFCellStyles.borderlessCell(c.getPhone())); } // return headerTable; }
/** * A helper method to create a PdfPCell. We can specify the content, font, horizontal alignment, * border (borderless, no bottom border, no right border, no top border, etc. * * @param content The text content to be displayed in the cell. * @param borderless boolean true if the cell should be borderless. * @param noBottom boolean true if the cell should have borderWidthBottom = 0. * @param noRight boolean true if the cell should have borderWidthRight = 0. * @param noTop boolean true if the cell should have borderWidthTop = 0. * @param horizontalAlignment The desired horizontal alignment for the cell. * @param font The font type to be used in the cell. * @return An instance of PdfPCell which content and attributes were set by the input parameters. */ private PdfPCell createCell( String content, boolean borderless, boolean noBottom, boolean noRight, boolean noTop, int horizontalAlignment, Font font) { PdfPCell tableCell = new PdfPCell(new Paragraph(content, font)); if (borderless) { tableCell.setBorder(0); } if (noBottom) { tableCell.setBorderWidthBottom(0); } if (noTop) { tableCell.setBorderWidthTop(0); } if (noRight) { tableCell.setBorderWidthRight(0); } tableCell.setHorizontalAlignment(horizontalAlignment); return tableCell; }
protected void apply(PdfPCell cell, RenderingContext context, PJsonObject params) { if (paddingLeft != null) cell.setPaddingLeft(paddingLeft.floatValue()); if (paddingRight != null) cell.setPaddingRight(paddingRight.floatValue()); if (paddingTop != null) cell.setPaddingTop(paddingTop.floatValue()); if (paddingBottom != null) cell.setPaddingBottom(paddingBottom.floatValue()); if (borderWidthLeft != null) cell.setBorderWidthLeft(borderWidthLeft.floatValue()); if (borderWidthRight != null) cell.setBorderWidthRight(borderWidthRight.floatValue()); if (borderWidthTop != null) cell.setBorderWidthTop(borderWidthTop.floatValue()); if (borderWidthBottom != null) cell.setBorderWidthBottom(borderWidthBottom.floatValue()); if (getBorderColorLeftVal(context, params) != null) cell.setBorderColorLeft(getBorderColorLeftVal(context, params)); if (getBorderColorRightVal(context, params) != null) cell.setBorderColorRight(getBorderColorRightVal(context, params)); if (getBorderColorTopVal(context, params) != null) cell.setBorderColorTop(getBorderColorTopVal(context, params)); if (getBorderColorBottomVal(context, params) != null) cell.setBorderColorBottom(getBorderColorBottomVal(context, params)); if (getBackgroundColorVal(context, params) != null) cell.setBackgroundColor(getBackgroundColorVal(context, params)); if (align != null) cell.setHorizontalAlignment(align.getCode()); if (vertAlign != null) cell.setVerticalAlignment(vertAlign.getCode()); }
private void addTable( JSONArray store, String[] res, String[] colIndex, String[] colHeader, String[] mainHeader, String[] val, Document document) throws JSONException, DocumentException { java.awt.Color tColor = new Color(0, 0, 0); fontSmallBold.setColor(tColor); Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor); float[] colw = new float[4]; for (int x = 0; x < 4; x++) { colw[x] = 150; } int col = 0; for (int x = 0; x < mainHeader.length; x++) { // table start PdfPTable table = new PdfPTable(colw); table.setTotalWidth(88); table.setWidthPercentage(colw, document.getPageSize()); // table.setSpacingBefore(10); PdfPTable mainTable = new PdfPTable(1); mainTable.setTotalWidth(90); mainTable.setWidthPercentage(100); mainTable.setSpacingBefore(20); // header cell for mainTable PdfPCell headcell = null; headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold)); headcell.setBackgroundColor(new Color(0xEEEEEE)); headcell.setPadding(padding); mainTable.addCell(headcell); document.add(mainTable); // header cell added to mainTable int row = 3; if (x == 0 || x == 4) { row = 4; } else if (x == 5) { row = 0; } for (; row > 0; row--) { for (int y = 1; y < colw.length + 1; y++) { // for each column add the colHeader and value cell if (col != colHeader.length) { if (y % 2 != 0) { Paragraph p = new Paragraph(colHeader[col], f1); if (colHeader[col].contains("Variance")) { p = new Paragraph(colHeader[col], fontSmallBold); } PdfPCell pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); } else { Paragraph p; p = new Paragraph(val[col], f1); if (colHeader[col].contains("Start Variance") || colHeader[col].contains("End Variance")) { p = new Paragraph(val[col] + " days", fontSmallBold); } else if (colHeader[col].contains("Duration")) { if (colHeader[col].contains("Duration Variance")) p = new Paragraph(val[col] + " days", fontSmallBold); else p = new Paragraph(val[col] + " days", f1); } else if (colHeader[col].contains("Work")) { if (colHeader[col].contains("Work Variance")) p = new Paragraph(val[col] + " hrs", fontSmallBold); else p = new Paragraph(val[col] + " hrs", f1); } else if (colHeader[col].contains("Cost")) { if (colHeader[col].contains("Cost Variance")) p = new Paragraph(currSymbol + " " + val[col], fontSmallBold); else p = new Paragraph(currSymbol + " " + val[col], f1); } else if (colHeader[col].contains("Percent Complete")) { p = new Paragraph(val[col] + " %", f1); } PdfPCell pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); col++; } } } } if (x == 5) { int y = 0; row = res.length / 4; for (; row > 0; row--) { for (int c = 0; c < 2; c++) { Paragraph p = new Paragraph(res[y], f1); PdfPCell pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); p = new Paragraph(res[y + 1], f1); pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); y += 2; } } } document.add(table); } }
public void getHeaderFooter(Document document) throws JSONException { java.awt.Color tColor = new Color(0, 0, 0); fontSmallRegular.setColor(tColor); java.util.Date dt = new java.util.Date(); String dformat = "yyyy-MM-d"; java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(dformat); String DateStr = dtf.format(dt); // -------- header ---------------- header = new PdfPTable(1); PdfPCell headerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular)); headerNotecell.setBorder(0); headerNotecell.setPaddingBottom(4); headerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER); header.addCell(headerNotecell); PdfPCell headerSeparator = new PdfPCell(new Phrase("")); headerSeparator.setBorder(PdfPCell.BOX); headerSeparator.setPadding(0); headerSeparator.setColspan(1); header.addCell(headerSeparator); // -------- header end ---------------- // -------- footer ------------------- footer = new PdfPTable(3); PdfPCell footerSeparator = new PdfPCell(new Phrase("")); footerSeparator.setBorder(PdfPCell.BOX); footerSeparator.setPadding(0); footerSeparator.setColspan(3); footer.addCell(footerSeparator); PdfPCell emptyCell = new PdfPCell(new Phrase("", fontSmallRegular)); emptyCell.setBorder(0); emptyCell.setColspan(1); emptyCell.setHorizontalAlignment(PdfCell.ALIGN_LEFT); footer.addCell(emptyCell); PdfPCell footerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular)); footerNotecell.setBorder(0); footerNotecell.setColspan(1); footerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER); footer.addCell(footerNotecell); PdfPCell pagerDateCell = new PdfPCell(new Phrase(DateStr, fontSmallRegular)); pagerDateCell.setBorder(0); pagerDateCell.setColspan(1); pagerDateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); footer.addCell(pagerDateCell); // -------- footer end ----------- }
public ByteArrayOutputStream create(Info in, Image toplogo) throws Exception { DocHelper dh = new DocHelper(); Document document = new Document(PageSize.LETTER); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setEncryption( PdfWriter.STRENGTH128BITS, "", "3p(0pdf", PdfWriter.AllowCopy | PdfWriter.AllowPrinting); // when creating based off this document, cut out from here--------------------- contract.next(); float amount = contract.getFloat("amount"); String job_name = contract.getString("job_name"); String company = contract.getString("company_name"); String costCode = contract.getString("division") + " " + contract.getString("cost_code"); String phaseCode = contract.getString("phase_code"); float change_order_num = 0; int sub_co_number = 0; String item_number = "0"; String co_desc, subject, status; float unit_amount = 0, unit_quantity = 0, net_cost = 0; float total = 0; DecimalFormat df = new DecimalFormat("$###,###,##0.00"); DecimalFormat codf = new DecimalFormat("0.##"); SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy"); // blank spacer for keeping tables apart PdfPTable spacer = new PdfPTable(1); /* spacer.setBorderWidth(0); spacer.setDefaultCellBorderWidth(0); spacer.setWidth(100); spacer.setPadding(0); spacer.setSpacing(0); */ PdfPCell blank = new PdfPCell( new Phrase("", new Font(Font.TIMES_ROMAN, 1, Font.BOLD, new Color(255, 255, 255)))); blank.setBorderWidth(0); // blank.setLeading(0); spacer.addCell(blank); // start of document Phrase p1 = new Phrase( "Printed: " + sdf.format(new java.util.Date()), new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)); HeaderFooter footer = new HeaderFooter(p1, false); footer.setAlignment(Element.ALIGN_CENTER); footer.setBorder(Rectangle.NO_BORDER); document.setFooter(footer); document.open(); Image blank1_0 = Image.getInstance(in.path + "/jsp/images/blank1_0.jpg"); blank1_0.scalePercent(60); toplogo.scalePercent(20); /* Table table1=new Table(1,1); table1.setBorderWidth(0); table1.setDefaultCellBorder(0); table1.setPadding(3); */ PdfPTable table1 = new PdfPTable(2); // t.setBorder(0); // t.setDefaultPdfPCellBorder(0); table1.setWidthPercentage(100); PdfPCell cell = new PdfPCell(toplogo); dh.top(cell); cell.setPaddingBottom(4); cell.setBorder(0); table1.addCell(cell); Phrase name = new Phrase(job_name + "\n", dh.font(16)); name.add(new Phrase("Subcontract CO Report", dh.font(14))); cell = new PdfPCell(name); dh.middle(cell); dh.center(cell); cell.setBorder(0); table1.addCell(cell); document.add(table1); table1 = new PdfPTable(1); table1.setWidthPercentage(100); p1 = new Phrase(costCode + "-" + phaseCode + ": " + company, dh.font(16, Font.BOLD)); cell = new PdfPCell(p1); cell.setUseDescender(true); dh.center(cell); dh.middle(cell); dh.gray(cell); cell.setBorder(0); table1.addCell(cell); document.add(table1); document.add(spacer); // header cells table1 = new PdfPTable(5); int[] widths1 = {5, 5, 57, 15, 15}; table1.setWidths(widths1); table1.setWidthPercentage(100); // data cells float grand_total = 0; while (item.next()) { change_order_num = item.getFloat("change_order_num"); sub_co_number = item.getInt("sub_co_number"); co_desc = item.getString("description"); if (co_desc == null) co_desc = ""; item_number = item.getString("item_number"); subject = item.getString("subject"); if (subject == null) subject = ""; unit_amount = item.getFloat("unit_amount"); unit_quantity = item.getFloat("unit_quantity"); status = item.getString("status"); // bonds_and_insurance = item.getFloat("bonds_and_insurance"); // item_tax = item.getFloat("item_tax"); // epco_markup = item.getFloat("epco_markup"); net_cost = (unit_amount * unit_quantity); if (status.equals("Approved")) { total += net_cost; grand_total += net_cost; } // first row table1.addCell(blank); if (change_order_num == -1) co_desc = "Backcharge"; if (change_order_num == 0) co_desc = ""; p1 = new Phrase(Integer.toString(sub_co_number), new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)); cell = new PdfPCell(p1); dh.top(cell); cell.setBackgroundColor(new Color(225, 225, 225)); cell.setBorder(0); table1.addCell(cell); cell = new PdfPCell(new Phrase(co_desc, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); cell.setColspan(2); dh.top(cell); cell.setBackgroundColor(new Color(225, 225, 225)); cell.setBorder(0); table1.addCell(cell); cell = new PdfPCell( new Phrase( "CO# " + codf.format(change_order_num) + "-" + item_number, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); dh.top(cell); dh.right(cell); cell.setBackgroundColor(new Color(225, 225, 225)); cell.setBorder(0); table1.addCell(cell); table1.addCell(blank); table1.addCell(blank); cell = new PdfPCell(new Phrase(subject, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); dh.top(cell); cell.setBorder(0); table1.addCell(cell); cell = new PdfPCell(new Phrase(df.format(net_cost), new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); dh.right(cell); dh.top(cell); cell.setBorder(0); table1.addCell(cell); cell = new PdfPCell(new Phrase(status, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); dh.right(cell); dh.top(cell); cell.setBorder(0); table1.addCell(cell); } // end while // Spit out final total row document.add(table1); document.add(spacer); table1 = new PdfPTable(3); int[] widths2 = {72, 15, 12}; table1.setWidths(widths2); cell = new PdfPCell( new Phrase( "Total Approved Change Orders:", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL))); dh.right(cell); dh.middle(cell); cell.setBorder(0); table1.addCell(cell); cell = new PdfPCell( new Phrase(df.format(grand_total), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL))); dh.right(cell); dh.middle(cell); cell.setBorder(0); table1.addCell(cell); table1.addCell(blank); cell = new PdfPCell( new Phrase("Original Contract Amount:", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL))); dh.right(cell); dh.middle(cell); cell.setBorder(0); table1.addCell(cell); cell = new PdfPCell(new Phrase(df.format(amount), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL))); dh.right(cell); dh.middle(cell); cell.setBorder(0); table1.addCell(cell); table1.addCell(blank); cell = new PdfPCell( new Phrase("Current Approved Total:", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL))); dh.right(cell); dh.middle(cell); cell.setBorder(0); table1.addCell(cell); grand_total += amount; cell = new PdfPCell(new Phrase(df.format(grand_total), new Font(Font.TIMES_ROMAN, 10, Font.BOLD))); dh.right(cell); dh.middle(cell); cell.setBorder(0); table1.addCell(cell); table1.addCell(blank); document.add(table1); if (contract != null) contract.getStatement().close(); contract = null; if (item != null) item.getStatement().close(); item = null; // -----------------------to here-------------------- document.close(); return baos; }
public void onStartPage(PdfWriter writer, Document document) { try { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); PdfPTable tab1 = new PdfPTable(1); // sub table 2 PdfPTable subtab2 = new PdfPTable(1); subtab2.setWidthPercentage(100); subtab2.addCell( printStr("SINGAPORE CONSULATE-GENERAL HONG KONG", 1, 25, true, PdfPCell.NO_BORDER, 1)); subtab2.addCell(printStr("Tel:2527 2212", 1, 25, true, PdfPCell.NO_BORDER, 1)); PdfPCell subcel2 = new PdfPCell(subtab2); subcel2.setColspan(1); subcel2.setHorizontalAlignment(subcel2.ALIGN_LEFT); subcel2.setBorder(subcel2.NO_BORDER); subcel2.setPaddingBottom(0.0f); tab1.addCell(subcel2); float[] widths = {80}; tab1.setWidths(widths); PdfPCell cel1 = new PdfPCell(tab1); cel1.setColspan(1); cel1.setHorizontalAlignment(cel1.ALIGN_LEFT); cel1.setBorder(cel1.NO_BORDER); cel1.setPaddingBottom(0.0f); cel1.setFixedHeight(120f); table.addCell(cel1); // col headers float[] widths4 = {80}; table.setWidths(widths4); Rectangle page = document.getPageSize(); table.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin()); table.writeSelectedRows(0, -1, 20, page.height() - 20 + table.getTotalHeight() - 90, cb); } catch (Exception e) { e.printStackTrace(); } }
public void createPdf() throws ClassNotFoundException, SQLException { /*Declaramos documento como un objeto Document Asignamos el tamaño de hoja y los margenes */ Document documento = new Document(PageSize.A4.rotate(), 1, 1, 20, 36); // writer es declarado como el método utilizado para escribir en el archivo PdfWriter writer = null; try { // Obtenemos la instancia del archivo a utilizar String filename = "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/documentos/reporteAutorizacion.pdf"; File fichero = new File(filename); if (fichero.exists()) { System.out.println("El fichero existe222222222"); fichero.delete(); System.out.println("El fichero elimino"); } else { System.out.println("el fichero no existe"); } writer = PdfWriter.getInstance(documento, new FileOutputStream(filename)); } catch (Exception ex) { System.out.println("NO creooooo"); ex.getMessage(); } // Declaramos una instancia de los eventos en HeaderFooter HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); // Agregamos un titulo al archivo documento.addTitle("ARCHIVO PDF"); // Agregamos el autor del archivo documento.addAuthor("PROVIAS NACIONAL"); // Abrimos el documento para edición documento.open(); try { // Declaramos un texto como Paragraph // Le podemos dar formado como alineación, tamaño y color a la fuente. Paragraph title1 = new Paragraph(); title1.setAlignment(Element.ALIGN_CENTER); PdfPTable ta1 = new PdfPTable(2); ta1.setHorizontalAlignment(Element.ALIGN_CENTER); ta1.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); ta1.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cel1 = new PdfPCell(); com.lowagie.text.Image image = com.lowagie.text.Image.getInstance("D:/Provias/images/imgExports.jpg"); // image.setWidthPercentage(500); cel1.addElement(image); cel1.setHorizontalAlignment(Element.ALIGN_CENTER); cel1.setVerticalAlignment(Element.ALIGN_MIDDLE); cel1.setBorder(Rectangle.NO_BORDER); ta1.addCell(cel1); PdfPCell cel2 = new PdfPCell(); cel2.addElement( new Phrase( "Reporte de Autorizaciones Especiales", FontFactory.getFont( FontFactory.HELVETICA, 12, Font.BOLD, new CMYKColor(0, 0, 0, 100)))); cel2.setFixedHeight(90); cel2.setHorizontalAlignment(Element.ALIGN_CENTER); cel2.setVerticalAlignment(Element.ALIGN_MIDDLE); cel2.setBorder(Rectangle.NO_BORDER); ta1.addCell(cel2); float[] columnWidths1 = new float[] {180f, 100f}; ta1.setWidths(columnWidths1); title1.add(ta1); // Agregamos el texto al documento documento.add(title1); // Agregamos un salto de linea documento.add(new Paragraph(" ")); // Agregamos la tabla al documento haciendo // la llamada al método tabla() documento.add(tabla()); } catch (Exception ex) { System.out.println("Por!!"); ex.getMessage(); } documento.close(); // Cerramos el documento writer.close(); // Cerramos writer }
/** * Imports the Cell properties into the PatchRtfCell * * @param cell The PdfPCell to import * @since 2.1.3 */ private void importCell(PdfPCell cell) { this.content = new ArrayList<RtfBasicElement>(); if (cell == null) { this.borders = new PatchRtfBorderGroup( this.document, PatchRtfBorder.CELL_BORDER, this.parentRow.getParentTable().getBorders()); return; } // padding this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding(); this.cellPaddingBottom = cell.getPaddingBottom(); this.cellPaddingTop = cell.getPaddingTop(); this.cellPaddingRight = cell.getPaddingRight(); this.cellPaddingLeft = cell.getPaddingLeft(); // BORDERS this.borders = new PatchRtfBorderGroup( this.document, PatchRtfBorder.CELL_BORDER, cell.getBorder(), cell.getBorderWidth(), cell.getBorderColor()); // border colors this.border = cell.getBorder(); this.borderColor = cell.getBorderColor(); this.borderColorBottom = cell.getBorderColorBottom(); this.borderColorTop = cell.getBorderColorTop(); this.borderColorLeft = cell.getBorderColorLeft(); this.borderColorRight = cell.getBorderColorRight(); // border widths this.borderWidth = cell.getBorderWidth(); this.borderWidthBottom = cell.getBorderWidthBottom(); this.borderWidthTop = cell.getBorderWidthTop(); this.borderWidthLeft = cell.getBorderWidthLeft(); this.borderWidthRight = cell.getBorderWidthRight(); this.colspan = cell.getColspan(); this.rowspan = 1; // cell.getRowspan(); // if(cell.getRowspan() > 1) { // this.mergeType = MERGE_VERT_PARENT; // } this.verticalAlignment = cell.getVerticalAlignment(); if (cell.getBackgroundColor() == null) { this.backgroundColor = new RtfColor(this.document, 255, 255, 255); } else { this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor()); } // does it have column composite info? java.util.List compositeElements = cell.getCompositeElements(); if (compositeElements != null) { Iterator cellIterator = compositeElements.iterator(); // does it have column info? Paragraph container = null; while (cellIterator.hasNext()) { try { Element element = (Element) cellIterator.next(); // should we wrap it in a paragraph if (!(element instanceof Paragraph) && !(element instanceof List)) { if (container != null) { container.add(element); } else { container = new Paragraph(); container.setAlignment(cell.getHorizontalAlignment()); container.add(element); } } else { if (container != null) { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element instanceof Paragraph && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) { ((Paragraph) element).setAlignment(cell.getHorizontalAlignment()); } RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } } catch (DocumentException de) { de.printStackTrace(); } } if (container != null) { try { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } catch (DocumentException de) { de.printStackTrace(); } } } // does it have image info? Image img = cell.getImage(); if (img != null) { try { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(img); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // does it have phrase info? Phrase phrase = cell.getPhrase(); if (phrase != null) { try { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(phrase); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // does it have table info? PdfPTable table = cell.getTable(); if (table != null) { this.add(table); // try { // RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(table); // for (int i = 0; i < rtfElements.length; i++) { // rtfElements[i].setInTable(true); // this.content.add(rtfElements[i]); // } // } catch (DocumentException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } }
public void geraCabecalhoPDF( final int tam, final GerencialItemInformationDTO gerencialItemDto, final PdfPTable tableParm, final PdfWriter writer, final Document document, final Rectangle page) { final PdfPTable table = new PdfPTable(tamTabela); table.setWidthPercentage(100); try { table.setWidths(tamanhoColunasReal); } catch (final DocumentException e1) { e1.printStackTrace(); } for (int j = 0; j < tam; j++) { final PdfPCell cell = new PdfPCell(); final GerencialFieldDTO fieldDto = (GerencialFieldDTO) ((List) gerencialItemDto.getListFields()).get(j); final GerencialGroupDTO grupoDefinicaoDto = this.fieldInGroupDefinition(fieldDto.getName(), gerencialItemDto.getListGroups()); if (grupoDefinicaoDto == null) { // So mostra se nao for um agrupador if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.String")) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); cell.setHorizontalAlignment(Element.ALIGN_LEFT); } if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.Double")) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.Integer")) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } if (fieldDto.getClassField().getName().equalsIgnoreCase("java.sql.Date")) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); cell.setHorizontalAlignment(Element.ALIGN_LEFT); } cell.setBackgroundColor(Color.GRAY); cell.setPhrase(new Phrase(fieldDto.getTitle())); table.addCell(cell); } } final PdfPCell celula0 = new PdfPCell(new Phrase(" ")); celula0.setColspan(2); celula0.setBorder(0); tableParm.addCell(celula0); final PdfPCell celula = new PdfPCell(table); celula.setColspan(2); tableParm.addCell(celula); }
/** * Create a PDF using the given input parameters. * * @param po The PurchaseOrderDocument to be used to create the pdf. * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf. * @param campusName The campus name to be used to generate the pdf. * @param contractManagerCampusCode The contract manager campus code to be used to generate the * pdf. * @param logoImage The logo image file name to be used to generate the pdf. * @param document The pdf document whose margins have already been set. * @param writer The PdfWriter to write the pdf document into. * @param environment The current environment used (e.g. DEV if it is a development environment). * @throws DocumentException */ private void createPOQuotePdf( PurchaseOrderDocument po, PurchaseOrderVendorQuote poqv, String campusName, String contractManagerCampusCode, String logoImage, Document document, PdfWriter writer, String environment) throws DocumentException { if (LOG.isDebugEnabled()) { LOG.debug("createQuotePdf() started for po number " + po.getPurapDocumentIdentifier()); } // These have to be set because they are used by the onOpenDocument() and onStartPage() methods. this.campusName = campusName; this.po = po; this.logoImage = logoImage; this.environment = environment; NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US); // Date format pattern: MM-dd-yyyy SimpleDateFormat sdf = PurApDateFormatUtils.getSimpleDateFormat( PurapConstants.NamedDateFormats.KUALI_SIMPLE_DATE_FORMAT_2); CampusParameter campusParameter = getCampusParameter(contractManagerCampusCode); String purchasingAddressFull = getPurchasingAddressFull(campusParameter); // Turn on the page events that handle the header and page numbers. PurchaseOrderQuotePdf events = new PurchaseOrderQuotePdf().getPageEvents(); writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc. document.open(); PdfPCell cell; Paragraph p = new Paragraph(); // ***** Info table (address, vendor, other info) ***** LOG.debug("createQuotePdf() info table started."); float[] infoWidths = {0.45f, 0.55f}; PdfPTable infoTable = new PdfPTable(infoWidths); infoTable.setWidthPercentage(100); infoTable.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.setSplitLate(false); p = new Paragraph(); ContractManager contractManager = po.getContractManager(); p.add(new Chunk("\n Return this form to:\n", ver_8_bold)); p.add(new Chunk(purchasingAddressFull + "\n", cour_10_normal)); p.add(new Chunk("\n", cour_10_normal)); p.add(new Chunk(" Fax #: ", ver_6_normal)); p.add(new Chunk(contractManager.getContractManagerFaxNumber() + "\n", cour_10_normal)); p.add(new Chunk(" Contract Manager: ", ver_6_normal)); p.add( new Chunk( contractManager.getContractManagerName() + " " + contractManager.getContractManagerPhoneNumber() + "\n", cour_10_normal)); p.add(new Chunk("\n", cour_10_normal)); p.add(new Chunk(" To:\n", ver_6_normal)); StringBuffer vendorInfo = new StringBuffer(); if (StringUtils.isNotBlank(poqv.getVendorAttentionName())) { vendorInfo.append(" ATTN: " + poqv.getVendorAttentionName().trim() + "\n"); } vendorInfo.append(" " + poqv.getVendorName() + "\n"); if (StringUtils.isNotBlank(poqv.getVendorLine1Address())) { vendorInfo.append(" " + poqv.getVendorLine1Address() + "\n"); } if (StringUtils.isNotBlank(poqv.getVendorLine2Address())) { vendorInfo.append(" " + poqv.getVendorLine2Address() + "\n"); } if (StringUtils.isNotBlank(poqv.getVendorCityName())) { vendorInfo.append(" " + poqv.getVendorCityName()); } if ((StringUtils.isNotBlank(poqv.getVendorStateCode())) && (!poqv.getVendorStateCode().equals("--"))) { vendorInfo.append(", " + poqv.getVendorStateCode()); } if (StringUtils.isNotBlank(poqv.getVendorAddressInternationalProvinceName())) { vendorInfo.append(", " + poqv.getVendorAddressInternationalProvinceName()); } if (StringUtils.isNotBlank(poqv.getVendorPostalCode())) { vendorInfo.append(" " + poqv.getVendorPostalCode() + "\n"); } else { vendorInfo.append("\n"); } if (!KFSConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(poqv.getVendorCountryCode()) && poqv.getVendorCountryCode() != null) { vendorInfo.append(" " + poqv.getVendorCountry().getName() + "\n\n"); } else { vendorInfo.append(" \n\n"); } p.add(new Chunk(vendorInfo.toString(), cour_10_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk("\n R.Q. Number: ", ver_8_bold)); p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal)); java.sql.Date requestDate = getDateTimeService().getCurrentSqlDate(); if (poqv.getPurchaseOrderQuoteTransmitTimestamp() != null) { try { requestDate = getDateTimeService().convertToSqlDate(poqv.getPurchaseOrderQuoteTransmitTimestamp()); } catch (ParseException e) { throw new RuntimeException( "ParseException thrown when trying to convert from Timestamp to SqlDate.", e); } } p.add(new Chunk(" R.Q. Date: ", ver_8_bold)); p.add(new Chunk(sdf.format(requestDate) + "\n", cour_10_normal)); p.add(new Chunk(" RESPONSE MUST BE RECEIVED BY: ", ver_8_bold)); if (po.getPurchaseOrderQuoteDueDate() != null) { p.add(new Chunk(sdf.format(po.getPurchaseOrderQuoteDueDate()) + "\n\n", cour_10_normal)); } else { p.add(new Chunk("N/A\n\n", cour_10_normal)); } // retrieve the quote stipulations StringBuffer quoteStipulations = getPoQuoteLanguage(); p.add(new Chunk(quoteStipulations.toString(), ver_6_normal)); p.add(new Chunk("\n ALL QUOTES MUST BE TOTALED", ver_12_normal)); cell = new PdfPCell(p); infoTable.addCell(cell); document.add(infoTable); // ***** Notes and Stipulations table ***** // The notes and stipulations table is type Table instead of PdfPTable // because Table has the method setCellsFitPage and I can't find an equivalent // in PdfPTable. Long notes or stipulations would break to the next page, leaving // a large white space on the previous page. PdfPTable notesStipulationsTable = new PdfPTable(1); notesStipulationsTable.setWidthPercentage(100); notesStipulationsTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Vendor Stipulations and Information\n\n", ver_6_normal)); if ((po.getPurchaseOrderBeginDate() != null) && (po.getPurchaseOrderEndDate() != null)) { p.add( new Chunk( " Order in effect from " + sdf.format(po.getPurchaseOrderBeginDate()) + " to " + sdf.format(po.getPurchaseOrderEndDate()) + ".\n", cour_10_normal)); } Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po.getPurchaseOrderVendorStipulations(); if (vendorStipulationsList.size() > 0) { StringBuffer vendorStipulations = new StringBuffer(); for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) { vendorStipulations.append(" " + povs.getVendorStipulationDescription() + "\n"); } p.add(new Chunk(" " + vendorStipulations.toString(), cour_10_normal)); } PdfPCell tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); document.add(notesStipulationsTable); // ***** Items table ***** LOG.debug("createQuotePdf() items table started."); float[] itemsWidths = {0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f}; PdfPTable itemsTable = new PdfPTable(6); // itemsTable.setCellsFitPage(false); With this set to true a large cell will // skip to the next page. The default Table behaviour seems to be what we want: // start the large cell on the same page and continue it to the next. itemsTable.setWidthPercentage(100); itemsTable.setWidths(itemsWidths); itemsTable.setSplitLate(false); tableCell = createCell("Item\nNo.", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Quantity", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("UOM", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Description", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell( "Unit Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell( "Extended Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); if (StringUtils.isNotBlank(po.getPurchaseOrderQuoteVendorNoteText())) { // Vendor notes line. itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = createCell( po.getPurchaseOrderQuoteVendorNoteText(), false, false, false, false, Element.ALIGN_LEFT, cour_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); } for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) po.getItems()) { if ((poi.getItemType() != null) && (StringUtils.isNotBlank(poi.getItemDescription())) && (poi.getItemType().isLineItemIndicator() || poi.getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) { // "ITEM"s display the line number; other types don't. String description = ""; description = (StringUtils.isNotBlank(poi.getItemCatalogNumber())) ? poi.getItemCatalogNumber().trim() + " - " : ""; description = description + ((StringUtils.isNotBlank(poi.getItemDescription())) ? poi.getItemDescription().trim() : ""); // If this is a full order discount item or trade in item, we add the // itemType description and a dash to the purchase order item description. if (StringUtils.isNotBlank(poi.getItemDescription())) { if (poi.getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) { description = poi.getItemType().getItemTypeDescription() + " - " + description; } } // We can do the normal table now because description is not too long. String itemLineNumber = new String(); if (poi.getItemType().isLineItemIndicator()) { itemLineNumber = poi.getItemLineNumber().toString(); } else { itemLineNumber = ""; } tableCell = createCell( itemLineNumber, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " "; tableCell = createCell(quantity, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); tableCell = createCell( poi.getItemUnitOfMeasureCode(), false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); tableCell = createCell(description, false, false, false, false, Element.ALIGN_LEFT, cour_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); } } // Blank line before totals createBlankRowInItemsTable(itemsTable); // Totals line. itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = createCell("Total: ", false, false, false, false, Element.ALIGN_RIGHT, ver_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); // Blank line after totals createBlankRowInItemsTable(itemsTable); document.add(itemsTable); LOG.debug("createQuotePdf() vendorFillsIn table started."); float[] vendorFillsInWidths = {0.50f, 0.50f}; PdfPTable vendorFillsInTable = new PdfPTable(vendorFillsInWidths); vendorFillsInTable.setWidthPercentage(100); vendorFillsInTable.setHorizontalAlignment(Element.ALIGN_CENTER); vendorFillsInTable.setSplitLate(false); vendorFillsInTable.getDefaultCell().setBorderWidth(0); vendorFillsInTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); vendorFillsInTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); // New row String important = new String( "\nIMPORTANT: The information and signature below MUST BE COMPLETED or your offer may be rejected.\n"); cell = createCell(important, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String cashDiscount = new String("Terms of Payment: Cash discount_________%_________Days-Net________Days\n"); cell = createCell(cashDiscount, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String fob = new String(" FOB: __ Destination (Title)\n"); cell = createCell(fob, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String freightVendor = new String(" __ Freight Vendor Paid (Allowed)\n"); cell = createCell(freightVendor, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String shipping = new String(" __ Shipping Point (Title)\n"); cell = createCell(shipping, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String freightPrepaid = new String(" __ Freight Prepaid & Added Amount $_________\n"); cell = createCell(freightPrepaid, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String commonCarrier = new String(" If material will ship common carrier, please provide the following:\n"); cell = createCell(commonCarrier, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String origin = new String( " Point of origin and zip code: ______________________ Weight: _________ Class: _________\n"); cell = createCell(origin, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row p = new Paragraph(); p.add(new Chunk(" Unless otherwise stated, all material to be shipped to ", ver_8_normal)); String purchasingAddressPartial; if (po.getAddressToVendorIndicator()) { purchasingAddressPartial = po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode(); } else { purchasingAddressPartial = po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode(); } p.add(new Chunk(purchasingAddressPartial + "\n", cour_10_normal)); cell = new PdfPCell(p); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidth(0); vendorFillsInTable.addCell(cell); // New row String offerEffective = new String(" Offer effective until (Date):_____________\n"); cell = createCell(offerEffective, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String deliverBy = new String(" Delivery can be made by (Date):_____________\n"); cell = createCell(deliverBy, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String sign = new String(" SIGN HERE:____________________________\n"); cell = createCell(sign, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String date = new String(" DATE:____________________________\n"); cell = createCell(date, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); // New row String name = new String(" PRINT NAME:____________________________\n"); cell = createCell(name, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String phone = new String(" PHONE:____________________________\n"); cell = createCell(phone, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); // New row String company = new String(" COMPANY:____________________________\n"); cell = createCell(company, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String fax = new String(" FAX:____________________________\n"); cell = createCell(fax, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); document.add(vendorFillsInTable); document.close(); LOG.debug("createQuotePdf()pdf document closed."); } // End of createQuotePdf()
@Override public void doBody(PdfWriter writer, Document docu) { { float[] colsSize = {1f, 1f, 1f}; PdfPTable table = new PdfPTable(colsSize); // table.setTotalWidth(90); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell = new PdfPCell(); addCell(table, "警語", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 3); addCell(table, "核發機關:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1); addCell(table, "核發案號:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1); addCell(table, "申請範圍:親等", cell, PDFReport.CELL_ALIGN_RIGHT, PDFReport.CELL_NO_BORDER, 1); addCell(table, "申請事由:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 3); addCell(table, "法令依據:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 3); addCell(table, "資料最後異動日期:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1); addCell(table, "列印日期:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1); addCell(table, " ", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1); table.setSpacingAfter(10); try { docu.add(table); } catch (DocumentException e) { e.printStackTrace(); } } for (int okok = 0; okok < 5; okok++) { float[] titleWidth = {1f}; PdfPTable table = new PdfPTable(titleWidth); table.setWidthPercentage(100); PdfPCell titalCell = new PdfPCell(); titalCell.setMinimumHeight(20); addCell( table, "親等關聯資料", titalCell, PDFReport.CELL_ALIGN_CENTER, PDFReport.CELL_NO_BORDER, 1, 16); titalCell.setMinimumHeight(5); try { docu.add(table); } catch (DocumentException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } table = new PdfPTable(new float[] {20f, 20f, 20f, 20f, 20f}); table.setWidthPercentage(100f); // 設定整體寬度 PdfPCell cell = new PdfPCell(); for (int ii = 0; ii < 77; ii++) { addCell(table, String.valueOf(ii), cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_BOX, 1); if (ii > 5 && (ii % 5 == 0)) { addCell( table, String.valueOf(ii), cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_BOX, 5); } } table.setSpacingAfter(15); try { docu.add(table); } catch (DocumentException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
@Override public void onEndPage(final PdfWriter writer, final Document document) { try { /* Adicionado o header */ final Rectangle page = document.getPageSize(); final PdfPTable header = new PdfPTable(1); header.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); header.setLockedWidth(true); header.getDefaultCell().setFixedHeight(55); header.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); final PdfPCell cellC = new PdfPCell(); cellC.setBorder(1); final PdfPTable tableContent = new PdfPTable(3); /* Adicionando a LogoMarca */ URL url = null; String caminho = ""; String urlInicial = ""; Image image = null; caminho = ParametroUtil.getValorParametroCitSmartHashMap( Enumerados.ParametroSistema.URL_LOGO_PADRAO_RELATORIO, ""); if ("".equals(caminho.trim()) || !UtilImagem.verificaSeImagemExiste(caminho)) { urlInicial = ParametroUtil.getValorParametroCitSmartHashMap( Enumerados.ParametroSistema.URL_Sistema, ""); caminho = urlInicial + "/imagens/logo/logo.png"; } try { url = new URL(caminho); final URLConnection conn = url.openConnection(); conn.connect(); } catch (final MalformedURLException e) { // the URL is not in a valid form e.printStackTrace(); url = null; } catch (final IOException e) { e.printStackTrace(); url = null; } if (url == null) { if (Constantes.getValue("CAMINHO_LOGO_CITGERENCIAL") != null) { try { url = new URL(Constantes.getValue("CAMINHO_LOGO_CITGERENCIAL")); } catch (final Exception e) { e.printStackTrace(); } } } if (url == null) { caminho = Constantes.getValue("SERVER_ADDRESS") + Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/logoPadraoRelatorio.png"; try { url = new URL(caminho); } catch (final Exception e) { e.printStackTrace(); } } if (url != null) { try { image = Image.getInstance(url); } catch (final BadElementException e) { e.printStackTrace(); } } if (image != null) { image.scaleAbsolute(150, 50); image.setAlignment(Image.RIGHT); final Chunk ck = new Chunk(image, -3, -25); final PdfPCell cell = new PdfPCell(); cell.addElement(ck); cell.setBorderWidth(0); cell.setRowspan(2); tableContent.addCell(cell); } else { tableContent.addCell("Citsmart"); } final String strCab = Constantes.getValue("TEXTO_1a_LINHA_CABECALHO_CITGERENCIAL"); if (strCab != null && !strCab.equalsIgnoreCase("")) { final PdfPCell cAux = new PdfPCell( new Phrase(strCab, new Font(Font.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); cAux.setColspan(2); cAux.setBorderWidth(1); cAux.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); tableContent.addCell(cAux); } /* Adicionado o Titulo do relatório */ final PdfPCell titulo = new PdfPCell( new Phrase(titleReport, new Font(Font.HELVETICA, 14, Font.BOLD, new Color(0, 0, 0)))); titulo.setColspan(2); titulo.setRowspan(1); titulo.setBorderWidth(0); titulo.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); tableContent.addCell(titulo); /* Adicionado o filtro */ String strFiltro = this.trataParameters(hshParameters, colParmsUtilizadosNoSQL, colDefinicaoParametros); if (strFiltro == null) { strFiltro = ""; } final PdfPCell cFiltro = new PdfPCell( new Phrase(strFiltro, new Font(Font.HELVETICA, 8, Font.NORMAL, new Color(0, 0, 0)))); cFiltro.setBorderWidth(0); cFiltro.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cFiltro.setColspan(2); tableContent.addCell(cFiltro); cellC.addElement(tableContent); header.addCell(tableContent); // Fim - Trata parametros if (!existeAgrupador) { if (listRetorno != null && listRetorno.size() > 0) { final Object[] row = (Object[]) listRetorno.get(0); this.geraCabecalhoPDF(row.length, gerencialItemDto, header, writer, document, page); } } if (page.getWidth() > 600) { if (!existeAgrupador) { header.writeSelectedRows(0, -1, 20, 565, writer.getDirectContent()); } else { header.writeSelectedRows(0, -1, 20, 585, writer.getDirectContent()); } } else { if (!existeAgrupador) { header.writeSelectedRows( 0, -1, 20, page.getHeight() - document.topMargin() + header.getTotalHeight(), writer.getDirectContent()); } else { header.writeSelectedRows(0, -1, 20, 805, writer.getDirectContent()); } } /* Adicionado o footer */ final PdfPTable footer = new PdfPTable(2); final String emissao = (String) hshParameters.get("citcorpore.comum.emissao"); final String pagina = (String) hshParameters.get("citcorpore.comum.pagina"); PdfPCell cAuxPageNumber = new PdfPCell( new Phrase( emissao + ": " + UtilDatas.convertDateToString( TipoDate.DATE_DEFAULT, UtilDatas.getDataAtual(), WebUtil.getLanguage(request)) + " " + UtilDatas.formatHoraFormatadaStr(UtilDatas.getHoraAtual()), new Font(Font.HELVETICA, 8, Font.NORMAL, new Color(0, 0, 0)))); cAuxPageNumber.setBorder(0); footer.addCell(cAuxPageNumber); cAuxPageNumber = new PdfPCell( new Phrase( pagina + ": " + writer.getPageNumber(), new Font(Font.HELVETICA, 8, Font.NORMAL, new Color(0, 0, 0)))); cAuxPageNumber.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cAuxPageNumber.setBorder(0); footer.addCell(cAuxPageNumber); footer.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); footer.writeSelectedRows( 0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (final Exception e) { throw new ExceptionConverter(e); } }