List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell
public PdfPCell getDefaultCell()
PdfPCell
that will be used as reference for all the addCell
methods except addCell(PdfPCell)
. From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * //from w w w . j a va 2 s . c om * ?? row * * @param e table element * @param t header table ? * @throws Exception */ public static void setTableRow(Element e, PdfPTable t) throws Exception { t.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT); for (Element e1 : e.getChild("row").getChildren()) { t.addCell(new Phrase(e1.getText(), fnNormal)); } }
From source file:com.automaster.autoview.server.servlet.TableHeader.java
/** * Adds a header to every page/* w w w . j a v a 2 s .c o m*/ * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(3); try { table.setWidths(new int[] { 24, 24, 2 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.addCell(header); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Pgina %d de", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.BOTTOM); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } }
From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java
License:Open Source License
protected PdfPTable getFooterTable(int x, int y) { PdfPTable table = new PdfPTable(1); table.setTotalWidth(537);/*from w ww. ja v a 2s.co m*/ table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(40); table.getDefaultCell().setBorder(Rectangle.TOP); table.getDefaultCell().setBorderColor(new BaseColor(221, 72, 20)); table.getDefaultCell().setBorderWidth(1); table.getDefaultCell().setPaddingLeft(0); table.getDefaultCell().setPaddingRight(0); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_JUSTIFIED); Phrase phrase = new Phrase(); phrase.add(new Chunk(bottomChunk1, bottomFontBold)); phrase.add(new Chunk(bottomChunk2, bottomFont)); table.addCell(phrase); return table; }
From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java
License:Open Source License
protected PdfPTable getIspLogoTable(int x, int y) { PdfPTable table = new PdfPTable(1); table.setTotalWidth(150);/*from w w w. j a v a 2 s .c o m*/ table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(40); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.addCell(isplogo); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableDeItens(List<ItemDeVenda> itens) throws DocumentException { PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 5, 1, 1, 1 }); table.setWidthPercentage(100f);//from www. j a v a2 s . co m table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Quantidade"); table.addCell("Valor UN"); table.addCell("Total"); table.getDefaultCell().setBackgroundColor(null); for (ItemDeVenda it : itens) { table.addCell(it.getDescricaoProduto()); table.addCell(new DecimalFormat("0.000").format(it.getQuantidade())); table.addCell(new DecimalFormat("0.00").format(it.getValorProduto())); table.addCell(new DecimalFormat("0.00").format(it.getTotal())); } return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableEstoqueProdutos(boolean valoresNegativos) throws DocumentException { double total_requisitado = 381624.18; Map<String, Double[]> saida = GeradorRelatorio.getRelatorioEstoqueProdutos(valoresNegativos); PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 5, 2, 1, 1 }); table.setWidthPercentage(100f);//from w w w . j a v a 2 s.co m table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Quantidade em Estoque"); table.addCell("Valor de Compra"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); double quantidade = 0, total = 0; List<String> c = new ArrayList<String>(); c.addAll(saida.keySet()); Collections.sort(c); for (String produto : c) { Double[] val = saida.get(produto); double qt, vc, sub; qt = val[0]; vc = val[1]; sub = val[0] * val[1]; if (qt > 0 && qt < 10000) { quantidade += qt; total += (qt * vc); table.addCell(produto); table.addCell(new DecimalFormat("0.000").format(qt)); table.addCell(new DecimalFormat("0.00").format(vc)); table.addCell(new DecimalFormat("0.00").format(qt * vc)); } else { continue; //table.addCell(new DecimalFormat("0.00").format(val[1])); //table.addCell(new DecimalFormat("0.000").format(0)); //table.addCell(new DecimalFormat("0.00").format(vc)); //table.addCell(new DecimalFormat("0.00").format(0)); } if (total_requisitado - 10 <= total && total <= total_requisitado + 10) { break; } } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); //table.addCell(OperacaoStringUtil.formatarStringValorIntegerEPonto( // saida.size()) + " Produtos"); //table.addCell(OperacaoStringUtil.formatarStringQuantidadeEPonto(quantidade) // + " Itens"); String tot = OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(381624.18); PdfPCell cel2 = new PdfPCell(new Paragraph(tot)); cel2.setColspan(2); cel2.setHorizontalAlignment(Element.ALIGN_CENTER); cel2.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cel2); //table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total)); //System.out.println(total); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableEstoqueProdutos(boolean valoresNegativos, boolean paraLista, List<String> codigos_retirados, double total_requisitado) throws DocumentException { //double total_requisitado = 381624.18; Map<String, Double[]> saida = GeradorRelatorio.getRelatorioEstoqueProdutos(valoresNegativos, codigos_retirados);//from w ww . j av a2s .c om PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 5, 2, 1, 1 }); table.setWidthPercentage(100f); table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Quantidade em Estoque"); table.addCell("Valor de Compra"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); double quantidade = 0, total = 0; List<String> c = new ArrayList<String>(); c.addAll(saida.keySet()); Collections.sort(c); for (String produto : c) { if (paraLista && total_requisitado <= total) { break; } Double[] val = saida.get(produto); double qt, vc, sub; qt = val[0]; vc = val[1]; sub = val[0] * val[1]; if (qt > 0 && qt < 10000) { quantidade += qt; total += (qt * vc); table.addCell(produto); table.addCell(new DecimalFormat("0.000").format(qt)); table.addCell(new DecimalFormat("0.00").format(vc)); table.addCell(new DecimalFormat("0.00").format(qt * vc)); } else { continue; //table.addCell(new DecimalFormat("0.00").format(val[1])); //table.addCell(new DecimalFormat("0.000").format(0)); //table.addCell(new DecimalFormat("0.00").format(vc)); //table.addCell(new DecimalFormat("0.00").format(0)); } } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); //table.addCell(OperacaoStringUtil.formatarStringValorIntegerEPonto( // saida.size()) + " Produtos"); //table.addCell(OperacaoStringUtil.formatarStringQuantidadeEPonto(quantidade) // + " Itens"); String tot = OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total_requisitado); PdfPCell cel2 = new PdfPCell(new Paragraph(tot)); cel2.setColspan(2); cel2.setHorizontalAlignment(Element.ALIGN_CENTER); cel2.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cel2); //table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total)); //System.out.println(total); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableBalancoProdutos(Date inicio, Date fim) throws DocumentException { Map<String, Double[]> saida = GeradorRelatorio.getRelatorioDetalhadoSaidaProduto(inicio, fim); PdfPTable table = new PdfPTable(5); table.setWidths(new int[] { 5, 1, 1, 1, 1 }); table.setWidthPercentage(100f);//from w ww . j a v a 2 s .com table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Estoque"); table.addCell("Compra"); table.addCell("Venda"); table.addCell("Lucro"); table.getDefaultCell().setBackgroundColor(null); double compra = 0, venda = 0, lucro = 0, qt = 0; List<String> c = new ArrayList<String>(); c.addAll(saida.keySet()); Collections.sort(c); for (String produto : c) { table.addCell(produto); Double[] val = saida.get(produto); compra += val[0]; venda += val[1]; lucro += val[3]; qt += val[2]; table.addCell(new DecimalFormat("0.000").format(val[2])); table.addCell(new DecimalFormat("0.00").format(val[0])); table.addCell(new DecimalFormat("0.00").format(val[1])); table.addCell(new DecimalFormat("0.00").format(val[3])); } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setColspan(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); table.addCell(saida.size() + " Produtos"); table.addCell(new DecimalFormat("0.000").format(qt)); table.addCell(new DecimalFormat("0.00").format(compra)); table.addCell(new DecimalFormat("0.00").format(venda)); table.addCell(new DecimalFormat("0.00").format(lucro)); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableDebitoClientes(double maiorQue) throws DocumentException { List<Object[]> debitos = GeradorRelatorio.getRelatorioClientesComDebitoMaiorQue(maiorQue); PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 5, 2 }); table.setWidthPercentage(100f);/* w ww. j av a 2 s .c o m*/ table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Cliente"); table.addCell("Dbito"); table.getDefaultCell().setBackgroundColor(null); double total = 0; for (Object[] d : debitos) { table.addCell((String) d[0]); double val = (double) d[1]; table.addCell(OperacaoStringUtil.formatarStringValorMoedaEPonto(val)); total += val; } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total)); table.addCell("Quantidade de Clientes"); table.addCell(OperacaoStringUtil.formatarStringValorInteger(debitos.size())); return table; }
From source file:com.dandymadeproductions.ajqvue.io.PDFDataTableDumpThread.java
License:Open Source License
public void run() { // Class Method Instances String title;//from w w w. j a v a 2 s .com Font titleFont; Font rowHeaderFont; Font tableDataFont; BaseFont rowHeaderBaseFont; PdfPTable pdfTable; PdfPCell titleCell; PdfPCell rowHeaderCell; PdfPCell bodyCell; Document pdfDocument; PdfWriter pdfWriter; ByteArrayOutputStream byteArrayOutputStream; int columnCount, rowNumber; int[] columnWidths; int totalWidth; Rectangle pageSize; ProgressBar dumpProgressBar; HashMap<String, String> summaryListTableNameTypes; DataExportProperties pdfDataExportOptions; String currentTableFieldName; String currentType, currentString; // Setup columnCount = summaryListTable.getColumnCount(); rowNumber = summaryListTable.getRowCount(); columnWidths = new int[columnCount]; pdfTable = new PdfPTable(columnCount); pdfTable.setWidthPercentage(100); pdfTable.getDefaultCell().setPaddingBottom(4); pdfTable.getDefaultCell().setBorderWidth(1); summaryListTableNameTypes = new HashMap<String, String>(); pdfDataExportOptions = DBTablesPanel.getDataExportProperties(); titleFont = new Font(pdfDataExportOptions.getFont()); titleFont.setStyle(Font.BOLD); titleFont.setSize((float) pdfDataExportOptions.getTitleFontSize()); titleFont.setColor(new BaseColor(pdfDataExportOptions.getTitleColor().getRGB())); rowHeaderFont = new Font(pdfDataExportOptions.getFont()); rowHeaderFont.setStyle(Font.BOLD); rowHeaderFont.setSize((float) pdfDataExportOptions.getHeaderFontSize()); rowHeaderFont.setColor(new BaseColor(pdfDataExportOptions.getHeaderColor().getRGB())); rowHeaderBaseFont = rowHeaderFont.getCalculatedBaseFont(false); tableDataFont = pdfDataExportOptions.getFont(); // Constructing progress bar. dumpProgressBar = new ProgressBar(exportedTable + " Dump"); dumpProgressBar.setTaskLength(rowNumber); dumpProgressBar.pack(); dumpProgressBar.center(); dumpProgressBar.setVisible(true); // Create a Title if Optioned. title = pdfDataExportOptions.getTitle(); if (!title.equals("")) { if (title.equals("EXPORTED TABLE")) title = exportedTable; titleCell = new PdfPCell(new Phrase(title, titleFont)); titleCell.setBorder(0); titleCell.setPadding(10); titleCell.setColspan(summaryListTable.getColumnCount()); titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pdfTable.addCell(titleCell); pdfTable.setHeaderRows(2); } else pdfTable.setHeaderRows(1); // Create Row Header. for (int i = 0; i < columnCount; i++) { currentTableFieldName = summaryListTable.getColumnName(i); rowHeaderCell = new PdfPCell(new Phrase(currentTableFieldName, rowHeaderFont)); rowHeaderCell.setBorderWidth(pdfDataExportOptions.getHeaderBorderSize()); rowHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); rowHeaderCell.setBorderColor(new BaseColor(pdfDataExportOptions.getHeaderBorderColor().getRGB())); pdfTable.addCell(rowHeaderCell); columnWidths[i] = Math.min(50000, Math.max(columnWidths[i], rowHeaderBaseFont.getWidth(currentTableFieldName + " "))); if (tableColumnTypeNameHashMap != null) summaryListTableNameTypes.put(Integer.toString(i), tableColumnTypeNameHashMap.get(currentTableFieldName)); else summaryListTableNameTypes.put(Integer.toString(i), "String"); } // Create the Body of Data. int i = 0; while ((i < rowNumber) && !dumpProgressBar.isCanceled()) { dumpProgressBar.setCurrentValue(i); // Collecting rows of data & formatting date & timestamps // as needed according to the Export Properties. if (summaryListTable.getValueAt(i, 0) != null) { for (int j = 0; j < summaryListTable.getColumnCount(); j++) { currentString = summaryListTable.getValueAt(i, j) + ""; currentString = currentString.replaceAll("\n", ""); currentString = currentString.replaceAll("\r", ""); currentType = summaryListTableNameTypes.get(Integer.toString(j)); // Format Date & Timestamp Fields as Needed. if ((currentType != null) && (currentType.equals("DATE") || currentType.equals("DATETIME") || currentType.indexOf("TIMESTAMP") != -1)) { if (!currentString.toLowerCase(Locale.ENGLISH).equals("null")) { int firstSpace; String time; // Dates fall through DateTime and Timestamps try // to get the time separated before formatting // the date. if (currentString.indexOf(" ") != -1) { firstSpace = currentString.indexOf(" "); time = currentString.substring(firstSpace); currentString = currentString.substring(0, firstSpace); } else time = ""; currentString = Utils.convertViewDateString_To_DBDateString(currentString, DBTablesPanel.getGeneralDBProperties().getViewDateFormat()); currentString = Utils.convertDBDateString_To_ViewDateString(currentString, pdfDataExportOptions.getPDFDateFormat()) + time; } } bodyCell = new PdfPCell(new Phrase(currentString, tableDataFont)); bodyCell.setPaddingBottom(4); if (currentType != null) { // Set Numeric Fields Alignment. if (currentType.indexOf("BIT") != -1 || currentType.indexOf("BOOL") != -1 || currentType.indexOf("NUM") != -1 || currentType.indexOf("INT") != -1 || currentType.indexOf("FLOAT") != -1 || currentType.indexOf("DOUBLE") != -1 || currentType.equals("REAL") || currentType.equals("DECIMAL") || currentType.indexOf("COUNTER") != -1 || currentType.equals("BYTE") || currentType.equals("CURRENCY")) { bodyCell.setHorizontalAlignment(pdfDataExportOptions.getNumberAlignment()); bodyCell.setPaddingRight(4); } // Set Date/Time Field Alignment. if (currentType.indexOf("DATE") != -1 || currentType.indexOf("TIME") != -1 || currentType.indexOf("YEAR") != -1) bodyCell.setHorizontalAlignment(pdfDataExportOptions.getDateAlignment()); } pdfTable.addCell(bodyCell); columnWidths[j] = Math.min(50000, Math.max(columnWidths[j], BASE_FONT.getWidth(currentString + " "))); } } i++; } dumpProgressBar.dispose(); // Check to see if any data was in the summary // table to even be saved. if (pdfTable.size() <= pdfTable.getHeaderRows()) return; // Create a document of the PDF formatted data // to be saved to the given output file. try { // Sizing & Layout totalWidth = 0; for (int width : columnWidths) totalWidth += width; if (pdfDataExportOptions.getPageLayout() == PDFExportPreferencesPanel.LAYOUT_PORTRAIT) pageSize = PageSize.A4; else { pageSize = PageSize.A4.rotate(); pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f)); pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f)); } pdfTable.setWidths(columnWidths); // Document pdfDocument = new Document(pageSize); byteArrayOutputStream = new ByteArrayOutputStream(); pdfWriter = PdfWriter.getInstance(pdfDocument, byteArrayOutputStream); pdfDocument.open(); pdfTemplate = pdfWriter.getDirectContent().createTemplate(100, 100); pdfTemplate.setBoundingBox(new com.itextpdf.text.Rectangle(-20, -20, 100, 100)); pdfWriter.setPageEvent(this); pdfDocument.add(pdfTable); pdfDocument.close(); // Outputting WriteDataFile.mainWriteDataString(fileName, byteArrayOutputStream.toByteArray(), false); } catch (DocumentException de) { if (Ajqvue.getDebug()) { System.out.println("Failed to Create Document Needed to Output Data. \n" + de.toString()); } } }