List of usage examples for com.itextpdf.text.pdf PdfPTable addCell
public void addCell(final Phrase phrase)
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 ww w . j ava 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.coderbd.pos.pdf.BarcodePdf.java
public void generateBarcodePdf(int amount) throws UnsupportedEncodingException { try {//from ww w .ja va 2s. c o m String filename = directory + "\\" + barcodeData + ".pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(barcodeData); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(3); float[] widths = { 0.45f, .10f, .45f }; pdfPTable.setWidths(widths); String codeName = getCodeName(shop.getShopName(), shop.getShopId(), amount); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Paragraph paragraph = new Paragraph(codeName); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.close(); } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); } }
From source file:com.coderbd.pos.pdf.BarcodePdf.java
public void generateBarcodePdf(boolean fixedRate, Product p) throws UnsupportedEncodingException { try {//w w w . ja v a 2s. c o m String filename = directory + "\\" + barcodeData + ".pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(barcodeData); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(3); float[] widths = { 0.45f, .10f, .45f }; pdfPTable.setWidths(widths); String codeName = getCodeName(shop.getShopName(), shop.getShopId(), (int) p.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Paragraph paragraph = new Paragraph(codeName); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.close(); } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); } }
From source file:com.coderbd.pos.pdf.CodePDF.java
public boolean genCodeVer2Pdf() throws UnsupportedEncodingException { if (isFixedRated == true) { barcodeQuantity = 12;/* w w w . j av a 2 s. c om*/ } else { barcodeQuantity = 15; } try { String filename = ""; if (isFixedRated) { filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf"; } else { filename = directory + "\\" + product.getProductBarcode() + ".pdf"; } Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(product.getProductBarcode()); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(7); pdfPTable.setWidthPercentage(98); float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f }; pdfPTable.setWidths(widths); String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(), (int) product.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); Paragraph paragraph = new Paragraph(codeName, titleArialFont); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont); PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph); fixedRateCell.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * */ if (isFixedRated == true) { pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); } /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.add(new Paragraph( "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName() + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(), titleArialFont)); document.close(); return true; } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); return false; } }
From source file:com.coderbd.pos.pdf.OrderReportPDF.java
public boolean genPdf() throws UnsupportedEncodingException { List<SupplierOrderProductReport> soprs = sor.getSupplierOrderProductReports(); IDBuilder idBuilder = new IDBuilder(); Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); try {// w w w. j a va 2 s. c o m String timestamp = idBuilder.getUniqueTimeStampID(); String filename = sor.getSupplier().getSupplierName() + "_O" + sor.getSupplierOrderId() + "_" + timestamp + ".pdf"; String filePath = directory + "\\" + filename; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); PdfPTable pdfPTable = new PdfPTable(5); pdfPTable.setWidthPercentage(90); float[] widths = { 0.40f, 0.13f, 0.15f, 0.15f, 0.17f }; pdfPTable.addCell(new Paragraph("Product Name", headerFont)); pdfPTable.addCell(new Paragraph("Buy Rate", headerFont)); pdfPTable.addCell(new Paragraph("Primary Qty", headerFont)); pdfPTable.addCell(new Paragraph("Unsold Qty", headerFont)); pdfPTable.addCell(new Paragraph("Unsold Amount", headerFont)); pdfPTable.setWidths(widths); for (SupplierOrderProductReport sopr : soprs) { SupplierOrderProduct sop = sopr.getSupplierOrderProduct(); String name = sop.getSupplierProductName(); Double rate = sop.getSupplierRate(); Integer pQty = sop.getSupplierProductQuantity(); Integer unQty = sopr.getUnSoldProductQuantity(); Double unAmount = sopr.getUnSoldProductAmount(); Paragraph nameParag = new Paragraph(name, innerFont); Paragraph buyRateParag = new Paragraph(rate.toString(), innerFont); Paragraph primaryQuantityParag = new Paragraph(pQty.toString(), innerFont); Paragraph unsoldQuantityParag = new Paragraph(unQty.toString(), innerFont); Paragraph unsoldAmountParag = new Paragraph(unAmount.toString(), innerFont); PdfPCell nameCell = new PdfPCell(nameParag); PdfPCell buyRateCell = new PdfPCell(buyRateParag); PdfPCell primaryQuantityCell = new PdfPCell(primaryQuantityParag); PdfPCell unsoldQuantityCell = new PdfPCell(unsoldQuantityParag); PdfPCell unsoldAmountCell = new PdfPCell(unsoldAmountParag); pdfPTable.addCell(nameCell); pdfPTable.addCell(buyRateCell); pdfPTable.addCell(primaryQuantityCell); pdfPTable.addCell(unsoldQuantityCell); pdfPTable.addCell(unsoldAmountCell); } document.add(getHeader()); document.add(pdfPTable); document.add(getFooter()); document.add(new Paragraph(" Report Generated: " + new Date().toString(), innerFont)); document.close(); return true; } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); return false; } }
From source file:com.coderbd.pos.pdf.OrderReportPDF.java
public PdfPTable getFooter() throws DocumentException { Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); PdfPTable pdfPTableFooter = new PdfPTable(2); pdfPTableFooter.setWidthPercentage(90); float[] widthsFooter = { 0.80f, 0.20f }; pdfPTableFooter.setWidths(widthsFooter); Paragraph totalSoldPara = new Paragraph("Total Sold: " + sor.getOrderTotalSoldAmount().toString(), headerFont);/*from www .j a v a2s . c o m*/ PdfPCell totalSoldCell = new PdfPCell(totalSoldPara); totalSoldCell.setBorder(Rectangle.NO_BORDER); Paragraph totalUnSoldPara = new Paragraph("Total UnSold: " + sor.getOrderTotalUnsoldAmount().toString(), headerFont); PdfPCell totalUnSoldCell = new PdfPCell(totalUnSoldPara); totalUnSoldCell.setBorder(Rectangle.NO_BORDER); Paragraph blankPara = new Paragraph(""); PdfPCell blankCell = new PdfPCell(blankPara); blankCell.setBorder(Rectangle.NO_BORDER); Double bill = sor.getTotalBill(); Double paid = sor.getTotalPaid(); Double due = bill - paid; Paragraph billPara = new Paragraph("BILL: " + bill.toString(), headerFont); PdfPCell billCell = new PdfPCell(billPara); billCell.setBorder(Rectangle.NO_BORDER); Paragraph paidPara = new Paragraph("PAID: " + paid.toString(), headerFont); PdfPCell paidCell = new PdfPCell(paidPara); paidCell.setBorder(Rectangle.NO_BORDER); Paragraph duePara = new Paragraph("DUE: " + due.toString(), headerFont); PdfPCell dueCell = new PdfPCell(duePara); dueCell.setBorder(Rectangle.NO_BORDER); pdfPTableFooter.addCell(totalSoldCell); pdfPTableFooter.addCell(billCell); pdfPTableFooter.addCell(totalUnSoldCell); pdfPTableFooter.addCell(paidCell); pdfPTableFooter.addCell(blankCell); pdfPTableFooter.addCell(dueCell); return pdfPTableFooter; }
From source file:com.coderbd.pos.pdf.OrderReportPDF.java
public PdfPTable getHeader() throws DocumentException { Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 12, Font.BOLD); PdfPTable tableHeader = new PdfPTable(1); tableHeader.setWidthPercentage(90);//from www .ja v a 2 s. c o m Paragraph supplierNamePara = new Paragraph(sor.getSupplier().getSupplierName(), headerFont); Paragraph addressPara = new Paragraph(sor.getSupplier().getSupplierAddress(), innerFont); Paragraph mobilePara = new Paragraph("Mobile: " + sor.getSupplier().getSupplierMobile(), innerFont); Paragraph orderPara = new Paragraph("Order: " + sor.getSupplierOrderId() + ", Time: " + sor.getOrderTime(), innerFont); PdfPCell supplierNameCell = new PdfPCell(); supplierNameCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); supplierNameCell.setBorder(Rectangle.NO_BORDER); supplierNameCell.addElement(supplierNamePara); PdfPCell addressCell = new PdfPCell(); addressCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); addressCell.setBorder(Rectangle.NO_BORDER); addressCell.addElement(addressPara); PdfPCell mobileCell = new PdfPCell(mobilePara); mobileCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); mobileCell.setBorder(Rectangle.NO_BORDER); mobileCell.addElement(mobilePara); PdfPCell orderCell = new PdfPCell(orderPara); orderCell.setBorder(Rectangle.NO_BORDER); PdfPCell bCell = new PdfPCell(new Paragraph(" ")); bCell.setBorder(Rectangle.NO_BORDER); tableHeader.addCell(supplierNameCell); tableHeader.addCell(addressCell); tableHeader.addCell(mobileCell); tableHeader.addCell(orderCell); tableHeader.addCell(bCell); return tableHeader; }
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);//www .j a v a2 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("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 ww. j a v a2s . 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("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);// w w w. j av a2 s .co m 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; }