List of usage examples for com.itextpdf.text Paragraph Paragraph
public Paragraph(float leading, String string)
Paragraph
with a certain String
and a certain leading. 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 ww . j a v a2s . co 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);/* w w w .j av a 2s . co 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);/* w ww.ja v a 2 s. co 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
public String gerarPdfDaVenda(Venda v, List<ItemDeVenda> itens, File destino) throws IOException { Document doc = new Document(); try {// w w w .java 2 s.c o m String path = a.getRelatorio().getCanonicalPath() + "/Venda_" + v.getId() + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.open(); String subTitulo = "Venda Realizada no dia " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(v.getDia().getTime()); try { inserirHead(doc, "Venda do Cliente " + v.getCliente().getNome(), subTitulo); } catch (NullPointerException ne) { inserirHead(doc, "Venda vista ID: " + v.getId(), subTitulo); } PdfPTable table = getTableDeItens(itens); doc.add(table); Paragraph p2 = new Paragraph("Total: " + new DecimalFormat("0.00").format(v.getTotal()) + " \n Funcionrio: " + v.getFuncionario().getNome(), new Font(Font.FontFamily.COURIER, 16, Font.BOLD)); doc.add(p2); doc.close(); Arquivo.copyFile(new File(path), destino); return destino.getAbsolutePath(); } catch (DocumentException e) { e.printStackTrace(); return ""; } }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
public String gerarPdfDaVenda(Venda v, List<ItemDeVenda> itens) { Document doc = new Document(); try {/* w w w . j av a 2s .c o m*/ String path = a.getRelatorio().getCanonicalPath() + "/Venda_" + v.getId() + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.open(); String subTitulo = "Venda Realizada no dia " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(v.getDia().getTime()); if (v.getCliente() != null) { inserirHead(doc, "Venda do Cliente " + v.getCliente().getNome(), subTitulo); } else {//venda a vista inserirHead(doc, "Venda Vista", subTitulo); } PdfPTable table = getTableDeItens(itens); doc.add(table); Paragraph p2 = new Paragraph("Total: " + new DecimalFormat("0.00").format(v.getTotal()) + " \n Funcionrio: " + v.getFuncionario().getNome(), new Font(Font.FontFamily.COURIER, 16, Font.BOLD)); doc.add(p2); doc.close(); return path; } catch (DocumentException | IOException e) { e.printStackTrace(); return ""; } }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
public void inserirHead(Document doc, String titulo, String subTitulo) throws MalformedURLException, DocumentException { Image img = null;// w ww . j a va2 s . c om try { img = Image.getInstance(IMG.class.getResource("logo_relatorio.png")); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); } catch (IOException e) { e.printStackTrace(); } Font f = new Font(Font.FontFamily.COURIER, 20, Font.BOLD); Paragraph p = new Paragraph(titulo, f); Paragraph p2 = new Paragraph(subTitulo, new Font(Font.FontFamily.COURIER, 16, Font.BOLD)); p.setAlignment(Element.ALIGN_CENTER); doc.add(p); doc.add(p2); }
From source file:com.deadormi.servlet.CreaPdfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww . j av a 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getQueryString(); Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length())); List<Utente> iscritti = null; List<Post> posts = null; Gruppo gruppo = null; Utente utente = null; String imageUrl = null; String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); try { iscritti = UtenteController.getUserByGroupId(request, gruppo_id); gruppo = GruppoController.getGruppoById(request, gruppo_id); } catch (SQLException ex) { log.error(ex); } // step 1: creation of a document-object Document document = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n"; Paragraph pIncipit = new Paragraph(incipit, FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK)); pIncipit.setAlignment(Element.ALIGN_CENTER); pIncipit.setSpacingAfter(10); document.add(pIncipit); String title = "Gruppo " + gruppo.getNome(); Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE)); pTitle.setAlignment(Element.ALIGN_CENTER); pTitle.setSpacingAfter(40); document.add(pTitle); PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente")); PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post")); PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post")); labelNome.setBorder(Rectangle.NO_BORDER); labelNumPost.setBorder(Rectangle.NO_BORDER); labelData.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < iscritti.size(); i++) { utente = iscritti.get(i); try { posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente()); } catch (SQLException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } if (utente.getNome_avatar() != null) { imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/" + utente.getId_utente() + "_" + utente.getNome_avatar(); ; } else { imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png"; } Image image = Image.getInstance(new URL(imageUrl)); image.scaleToFit(50, 50); PdfPTable table = new PdfPTable(3); PdfPCell cellAvatar = new PdfPCell(image); cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER); cellAvatar.setBorder(Rectangle.NO_BORDER); cellAvatar.setRowspan(3); PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + "")); cellNome.setBorder(Rectangle.NO_BORDER); PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + "")); cellNumPost.setBorder(Rectangle.NO_BORDER); //L'ultimo sempre il piu recente siccome la query ORDER BY data_creazione PdfPCell cellData; if (posts.size() != 0) { cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione())); } else { cellData = new PdfPCell(new Paragraph("N/A")); } cellData.setBorder(Rectangle.NO_BORDER); PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" ")); cellVoidBottom.setBorder(Rectangle.BOTTOM); cellVoidBottom.setPaddingBottom(10); cellVoidBottom.setColspan(3); PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" ")); cellVoidTop.setBorder(Rectangle.NO_BORDER); cellVoidTop.setPaddingTop(10); cellVoidTop.setColspan(3); table.addCell(cellVoidTop); table.addCell(cellAvatar); table.addCell(labelNome); table.addCell(cellNome); table.addCell(labelNumPost); table.addCell(cellNumPost); table.addCell(labelData); table.addCell(cellData); table.addCell(cellVoidBottom); document.add(table); } document.close(); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf"); OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.debashubham.dumpy.ChainageCalcActivity.java
private void createTable(Section subCatPart) throws DocumentException { PdfPTable entry_table = new PdfPTable(10); entry_table.setWidthPercentage(100); // entry_table.setWidths(new float[]{0.25f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,1.0f}); PdfPCell id = new PdfPCell(new Phrase("Station Point")); id.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell left_row = new PdfPCell(new Phrase("CH. Left(m)")); left_row.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell center_row = new PdfPCell(new Phrase("CH. Center(m)")); center_row.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell right_row = new PdfPCell(new Phrase("CH. Right(m)")); right_row.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell bs = new PdfPCell(new Phrase("BS(m)")); bs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell is = new PdfPCell(new Phrase("IS(m)")); is.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell fs = new PdfPCell(new Phrase("FS(m)")); fs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell hi = new PdfPCell(new Phrase("HI(m)")); hi.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rl = new PdfPCell(new Phrase("RL(m)")); rl.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell remarks = new PdfPCell(new Phrase("REMARKS")); remarks.setHorizontalAlignment(Element.ALIGN_CENTER); entry_table.addCell(id);//from w w w.ja v a2 s .co m entry_table.addCell(left_row); entry_table.addCell(center_row); entry_table.addCell(right_row); entry_table.addCell(bs); entry_table.addCell(is); entry_table.addCell(fs); entry_table.addCell(hi); entry_table.addCell(rl); entry_table.addCell(remarks); entry_table.setHeaderRows(1); int largest = rl_list.size(); Log.e("Total RL:", String.valueOf(largest)); double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0; for (int i = 1; i <= largest; i++) { entry_table.addCell(String.valueOf(i)); if (i == 1) first_rl = rl_list.get(i); if (i == largest) last_rl = rl_list.get(i); if (left.containsKey(i)) { entry_table.addCell(String.valueOf(left.get(i))); entry_table.addCell(""); entry_table.addCell(""); } else if (center.containsKey(i)) { entry_table.addCell(""); entry_table.addCell(String.valueOf(center.get(i))); entry_table.addCell(""); } else if (right.containsKey(i)) { entry_table.addCell(""); entry_table.addCell(""); entry_table.addCell(String.valueOf(right.get(i))); } else { entry_table.addCell(""); entry_table.addCell(""); entry_table.addCell(""); } if (bs_list.containsKey(i)) { entry_table.addCell(String.valueOf(bs_list.get(i))); total_bs += bs_list.get(i); Log.e("TABLE:", "BS"); } else { entry_table.addCell(""); Log.e("TABLE:", "BS not entered"); } if (is_list.containsKey(i)) { entry_table.addCell(String.valueOf(is_list.get(i))); Log.e("TABLE:", "IS"); } else { entry_table.addCell(""); Log.e("TABLE:", "IS not entered"); } if (fs_list.containsKey(i)) { entry_table.addCell(String.valueOf(fs_list.get(i))); total_fs += fs_list.get(i); Log.e("TABLE:", "FS"); } else { entry_table.addCell(""); Log.e("TABLE:", "FS not entered"); } if (hi_list.containsKey(i)) { entry_table.addCell(String.valueOf(hi_list.get(i))); Log.e("TABLE:", "HI"); } else { entry_table.addCell(""); Log.e("TABLE:", "HI not entered"); } if (rl_list.containsKey(i)) { entry_table.addCell(String.valueOf(rl_list.get(i))); Log.e("TABLE:", "RL"); } else { entry_table.addCell(""); Log.e("TABLE:", "RL not entered"); } if (remarks_list.containsKey(i)) { entry_table.addCell(String.valueOf(remarks_list.get(i))); Log.e("TABLE:", "REMARKS"); } else { entry_table.addCell(""); Log.e("TABLE:", "REMARKS not entered"); } } subCatPart.add(entry_table); Log.e("Total BS:", String.valueOf(total_bs)); Log.e("Total FS:", String.valueOf(total_fs)); Log.e("First RL:", String.valueOf(first_rl)); Log.e("Last RL:", String.valueOf(last_rl)); Paragraph check_para = new Paragraph("Arithmetic Check:", subFont); addEmptyLine(check_para, 2); check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL"); addEmptyLine(check_para, 1); double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0; double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0; boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false; check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff)); addEmptyLine(check_para, 1); if (checktrue) { check_para.setSpacingBefore(20); check_para.add("OK"); } else { check_para.setSpacingBefore(20); check_para.add("Check Fail!"); } addEmptyLine(check_para, 1); check_para.add("_______________________________________________________"); subCatPart.add(check_para); Paragraph legend_para = new Paragraph("LEGEND:", subFont); addEmptyLine(legend_para, 1); legend_para.add("BS : Back Sight"); addEmptyLine(legend_para, 1); legend_para.add("IS : Intermediate Sight"); addEmptyLine(legend_para, 1); legend_para.add("FS : Fore Sight"); addEmptyLine(legend_para, 1); legend_para.add("HI : Height of Instrument"); addEmptyLine(legend_para, 1); legend_para.add("RL : Reduced Level"); addEmptyLine(legend_para, 1); legend_para.add("CH. : Chainage"); subCatPart.add(legend_para); }
From source file:com.debashubham.dumpy.SimpleCalcActivity.java
private void createTable(Section subCatPart) throws BadElementException { PdfPTable entry_table = new PdfPTable(7); entry_table.setWidthPercentage(100); PdfPCell id = new PdfPCell(new Phrase("Station Point")); id.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell bs = new PdfPCell(new Phrase("BS")); bs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell is = new PdfPCell(new Phrase("IS")); is.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell fs = new PdfPCell(new Phrase("FS")); fs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell hi = new PdfPCell(new Phrase("HI")); hi.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rl = new PdfPCell(new Phrase("RL")); rl.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell remarks = new PdfPCell(new Phrase("REMARKS")); remarks.setHorizontalAlignment(Element.ALIGN_CENTER); entry_table.addCell(id);//from w w w . jav a 2 s . co m entry_table.addCell(bs); entry_table.addCell(is); entry_table.addCell(fs); entry_table.addCell(hi); entry_table.addCell(rl); entry_table.addCell(remarks); entry_table.setHeaderRows(1); int largest = rl_list.size(); Log.e("Total RL:", String.valueOf(largest)); double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0; for (int i = 1; i <= largest; i++) { entry_table.addCell(String.valueOf(i)); if (i == 1) first_rl = rl_list.get(i); if (i == largest) last_rl = rl_list.get(i); if (bs_list.containsKey(i)) { entry_table.addCell(String.valueOf(bs_list.get(i))); total_bs += bs_list.get(i); Log.e("TABLE:", "BS"); } else { entry_table.addCell(""); Log.e("TABLE:", "BS not entered"); } if (is_list.containsKey(i)) { entry_table.addCell(String.valueOf(is_list.get(i))); Log.e("TABLE:", "IS"); } else { entry_table.addCell(""); Log.e("TABLE:", "IS not entered"); } if (fs_list.containsKey(i)) { entry_table.addCell(String.valueOf(fs_list.get(i))); total_fs += fs_list.get(i); Log.e("TABLE:", "FS"); } else { entry_table.addCell(""); Log.e("TABLE:", "FS not entered"); } if (hi_list.containsKey(i)) { entry_table.addCell(String.valueOf(hi_list.get(i))); Log.e("TABLE:", "HI"); } else { entry_table.addCell(""); Log.e("TABLE:", "HI not entered"); } if (rl_list.containsKey(i)) { entry_table.addCell(String.valueOf(rl_list.get(i))); Log.e("TABLE:", "RL"); } else { entry_table.addCell(""); Log.e("TABLE:", "RL not entered"); } if (remarks_list.containsKey(i)) { entry_table.addCell(String.valueOf(remarks_list.get(i))); Log.e("TABLE:", "REMARKS"); } else { entry_table.addCell(""); Log.e("TABLE:", "REMARKS not entered"); } } subCatPart.add(entry_table); Log.e("Total BS:", String.valueOf(total_bs)); Log.e("Total FS:", String.valueOf(total_fs)); Log.e("First RL:", String.valueOf(first_rl)); Log.e("Last RL:", String.valueOf(last_rl)); Paragraph check_para = new Paragraph("Arithmetic Check:", subFont); addEmptyLine(check_para, 2); check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL"); addEmptyLine(check_para, 1); double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0; double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0; boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false; check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff)); addEmptyLine(check_para, 1); if (checktrue) { check_para.setSpacingBefore(20); check_para.add("OK"); } else { check_para.setSpacingBefore(20); check_para.add("Check Fail!"); } addEmptyLine(check_para, 1); check_para.add("_______________________________________________________"); subCatPart.add(check_para); Paragraph legend_para = new Paragraph("LEGEND:", subFont); addEmptyLine(legend_para, 2); legend_para.add("BS : Back Sight"); addEmptyLine(legend_para, 1); legend_para.add("IS : Intermediate Sight"); addEmptyLine(legend_para, 1); legend_para.add("FS : Fore Sight"); addEmptyLine(legend_para, 1); legend_para.add("HI : Height of Instrument"); addEmptyLine(legend_para, 1); legend_para.add("RL : Reduced Level"); subCatPart.add(legend_para); }
From source file:com.devox.GUI.PDF.CrearReporteApto.java
@Override public void crear(File file) { try {// w ww. ja v a 2s.c o m document = new Document(PageSize.A4.rotate()); file.createNewFile(); writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); writer.setPageEvent(event); document.setMargins(30, 30, 40, 360); document.newPage(); Paragraph p = new Paragraph("RELACIN DE PRODUCTO APTO", FUENTE_TITULO_APTO); p.setAlignment(Element.ALIGN_CENTER); document.add(p); document.add(configurarInformacion()); PdfPTable table = crearTabla(); agregarProductos(table); document.add(table); document.close(); } catch (IOException | DocumentException ex) { Log.print(ex); } Object[] options = { "Abrir PDF", "No" }; int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options, options[0]); if (open == JOptionPane.YES_OPTION) { try { Desktop.getDesktop().open(file); } catch (IOException ex) { Log.print("No se encontr la ruta"); JOptionPane.showMessageDialog(null, "Error en el archivo"); } } }