List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:client.welcome3.java
private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed Document doc = new Document(); PdfWriter docWriter = null;// w ww .j a v a2 s. co m int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1); DecimalFormat df = new DecimalFormat("0.00"); //Date d = Calendar.getInstance().getTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); try { //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); //file path String dt = dateFormat.format(date); sFileName = "Report No- " + repID + " Project Report- " + dt + " Status " + report_status + " .pdf"; String path = "src/ProjectReports/" + sFileName; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm"); String d = dateFormat3.format(Calendar.getInstance().getTime()); //document header attributes doc.addCreationDate(); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy"); String sd2 = dateFormat2.format(pBeginDateChooser.getDate()); String ed2 = dateFormat2.format(pEndDateChooser.getDate()); Image image = Image.getInstance("src/Images/logo for pdf.png"); Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Paragraph paragraph = new Paragraph(); Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d + "\nYou can see all projects from " + sd2 + " to " + ed2); image.setAlignment(Image.RIGHT); doc.add(image); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); //insert column headings insertCell(table, "Project ID", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Project Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Start Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Due Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Status", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/ //create section heading by cell merging /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/ /*double orderTotal, total = 0;*/ String add1, add2, add3, add4, add5; DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); String sd = dateFormat1.format(pBeginDateChooser.getDate()); String ed = dateFormat1.format(pEndDateChooser.getDate()); if (report_status.equals("All")) { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where status = '" + report_status + "' and due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } //add the PDF table to the paragraph paragraph2.add(table); // add the paragraph to the document doc.add(new Paragraph("\nProject Status Report " + dt + "\n", font1)); doc.add(paragraph2); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!"); } if (docWriter != null) { //close the writer docWriter.close(); } } saveToDB(report_status, date, repID); }
From source file:climbingcompranking.model.ranking.RankingGenerator.java
License:Open Source License
public void createRankingPDF(String competitionName, CompetitionType compType) { doTheRanking(compType);/*from www .j a v a2 s . c o m*/ try { Document document = new Document(PageSize.A4.rotate()); // Landscape Date date = new Date(); String dateStr = ""; if (Locale.getDefault().equals(Locale.FRANCE)) { dateStr = new SimpleDateFormat("dd-MM-yyyy").format(date); } else { dateStr = new SimpleDateFormat("yyyy-MM-dd").format(date); } PdfWriter.getInstance(document, new FileOutputStream("data/pdf/" + competitionName + '-' + dateStr + ".pdf")); document.open(); // Meta data document.addTitle(competitionName); document.addSubject(competitionName + " ranking."); document.addKeywords(competitionName + ", ranking, climbingcompetition, climbcompranking"); document.addAuthor("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking"); document.addCreator("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking"); document.addCreationDate(); document.setMargins(0, 0, 0, 0); PdfPCell club = new PdfPCell(new Phrase(I18n.MODEL.getString("Club"))); PdfPCell climberName = new PdfPCell(new Phrase(I18n.MODEL.getString("ClimberName"))); PdfPCell ranking = new PdfPCell(new Phrase(I18n.MODEL.getString("Ranking"))); for (Map.Entry<Category, ArrayList<Climber>> climbersCategory : climbersMap.entrySet()) { if (climbersCategory.getValue().isEmpty()) continue; document.newPage(); // Title Paragraph title = new Paragraph( competitionName + " : " + climbersCategory.getKey().getCategoryName()); title.setAlignment(Element.ALIGN_CENTER); title.setFont(new Font(Font.FontFamily.HELVETICA, 36)); title.setSpacingAfter(20); // Table PdfPTable table = null; switch (compType) { case BOULDERING: case LEAD: case SPEED: table = new PdfPTable(3); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case LEAD_AND_BOULDERING: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case SPEED_AND_BOULDERING: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case SPEED_AND_LEAD: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case COMBINED: table = new PdfPTable(7); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; } // Alignment for (PdfPRow row : table.getRows()) { PdfPCell[] cells = row.getCells(); for (PdfPCell cellToAlign : cells) { cellToAlign.setHorizontalAlignment(Element.ALIGN_CENTER); cellToAlign.setVerticalAlignment(Element.ALIGN_CENTER); } } table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setHeaderRows(1); document.add(title); document.add(table); } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(RankingGenerator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java
License:Apache License
private void createHeaderRow(PdfExportParams entity, PdfPTable table, int feildLength) { PdfPCell iCell = new PdfPCell(new Phrase(entity.getTitle(), styler.getFont(null, entity.getTitle()))); iCell.setHorizontalAlignment(Element.ALIGN_CENTER); iCell.setVerticalAlignment(Element.ALIGN_CENTER); iCell.setFixedHeight(entity.getTitleHeight()); iCell.setColspan(feildLength + 1);// ww w . j av a 2 s . com table.addCell(iCell); if (entity.getSecondTitle() != null) { iCell = new PdfPCell( new Phrase(entity.getSecondTitle(), styler.getFont(null, entity.getSecondTitle()))); iCell.setHorizontalAlignment(Element.ALIGN_RIGHT); iCell.setVerticalAlignment(Element.ALIGN_CENTER); iCell.setFixedHeight(entity.getSecondTitleHeight()); iCell.setColspan(feildLength + 1); table.addCell(iCell); } }
From source file:cn.afterturn.easypoi.pdf.styler.PdfExportStylerDefaultImpl.java
License:Apache License
@Override public void setCellStyler(PdfPCell iCell, ExcelExportEntity entity, String text) { iCell.setHorizontalAlignment(Element.ALIGN_CENTER); iCell.setVerticalAlignment(Element.ALIGN_MIDDLE); }
From source file:com.afrisoftech.lib.HeaderFooterHelper.java
public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); // Phrase header = new Phrase("this is a header", ffont); // Phrase footer = new Phrase("this is a footer", ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, header, (document.right() - document.left()) / 2 + document.leftMargin(), document.top() + 10, 0); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(footer.getContent() + " " + String.valueOf(writer.getPageNumber())), (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 10, 0); }
From source file:com.ainfosec.macresponse.report.PdfGenerator.java
License:Open Source License
private static void createDataSection(Paragraph paragraph, DisplayObject displayObject) { if (displayObject == null || displayObject.getObjects() == null) { return;//from w w w.ja v a 2 s. c o m } // See if the DisplayObject has a list or a single object if (displayObject.getObjects().size() == 1) { TreeObject treeObject = displayObject.getObjects().get(0); // There's only 1 item // For each column, create/add a label with the title and the data int i = 0; for (String columnName : displayObject.getColumnNames()) { StringBuffer sb = new StringBuffer(); // Add the column title sb.append(displayObject.getColumnTitles()[i]); sb.append(": "); // Get the value of the field try { Field field = treeObject.getClass().getDeclaredField(columnName); String val = (String) field.get(treeObject); if (val == null) { val = ""; } // Add the value sb.append(val); sb.append("\n"); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Put the string into the paragraph paragraph.add(sb.toString()); i++; } } else { PdfPTable table = new PdfPTable(displayObject.getColumnTitles().length); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_CENTER); for (String columnName : displayObject.getColumnTitles()) { table.getDefaultCell().setBackgroundColor(BaseColor.CYAN); table.addCell(columnName); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); } for (TreeObject to1 : displayObject.getObjects()) { for (String columnName : displayObject.getColumnNames()) { try { Field field = to1.getClass().getDeclaredField(columnName); String val = (String) field.get(to1); if (val == null) { val = ""; } table.addCell(val); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } table.getDefaultCell().setColspan(displayObject.getColumnTitles().length); table.getDefaultCell().setBorder(SWT.NONE); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // TODO Paul number the tables table.addCell("Table: " + displayObject.getTitle()); paragraph.add(table); } }
From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java
public void addTableColumns(String[] cols, PdfPTable table) { if (cols != null) { for (String colName : cols) { PdfPCell cell = new PdfPCell(new Phrase(colName, smallerBoldFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0.8f);//from w ww .j a v a2 s . co m table.addCell(cell); } } }
From source file:com.app.gpo.pdf.utils.PDForderLabelCard.java
License:Open Source License
@Override protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { // get data model which is passed by the Spring container OrderItem orderItem = (OrderItem) model.get("orderItem"); Font font = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); font.setSize(20);//from ww w . ja v a 2 s . co m Font font2 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); font2.setSize(12); String utf = orderItem.getorderItemName(); byte[] data = utf.getBytes("CP1250"); String ascii = new String(data); String code = orderItem.getorderNumber(); Paragraph numberText = new Paragraph(code, font); numberText.setAlignment(Element.ALIGN_CENTER); doc.add(new Phrase("\n")); Paragraph nameText = new Paragraph(ascii, font2); nameText.setAlignment(Element.ALIGN_CENTER); // document.newPage() /*BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.CODE128); barcode.setCode(code); Rectangle barcodeRect = new Rectangle(400,200); barcode.placeBarcode(barcodeRect, BaseColor.BLACK, BaseColor.YELLOW); doc.add(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY));*/ doc.add(numberText); doc.add(new Phrase("\n")); doc.add(nameText); }
From source file:com.app.gpo.pdf.utils.PDForderLabelCards.java
License:Open Source License
@Override protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { // get data model which is passed by the Spring container List<OrderItem> orderItemList = (List<OrderItem>) model.get("orderItemList"); Font font = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); font.setSize(18);/*from w ww . ja v a 2 s .com*/ Font font2 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); font2.setSize(12); Iterator<OrderItem> it = orderItemList.iterator(); while (it.hasNext()) { OrderItem orderItem = it.next(); String utf = orderItem.getorderItemName(); byte[] data = utf.getBytes("CP1250"); String ascii = new String(data); String code = orderItem.getorderNumber(); Paragraph numberText = new Paragraph(code, font); numberText.setAlignment(Element.ALIGN_CENTER); doc.add(new Phrase("\n")); Paragraph nameText = new Paragraph(ascii, font2); nameText.setAlignment(Element.ALIGN_CENTER); // document.newPage() /*BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.CODE128); barcode.setCode(code); Rectangle barcodeRect = new Rectangle(400,200); barcode.placeBarcode(barcodeRect, BaseColor.BLACK, BaseColor.YELLOW); doc.add(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY));*/ doc.add(numberText); doc.add(new Phrase("\n")); doc.add(nameText); doc.newPage(); } }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void createTable(Document document) throws DocumentException, MalformedURLException, IOException { PdfPTable table = new PdfPTable(8); table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); // addLogo(table); String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule", "Price" }; Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); for (String header : headerTitle) { Phrase p = new Phrase(header, headerFont); PdfPCell c1 = new PdfPCell(p); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setLeading(0f, 1.5f);/*from ww w. j ava 2s. c o m*/ c1.setBackgroundColor(BaseColor.GRAY); table.addCell(c1); } Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f); MedicineUtility mUtil = new MedicineUtility(); // table.setSpacingAfter(20); double vat = 0.0; double discount = 0.0; int count = 1; double totalAmt = 0.0; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { // replaceDoctor = iBean.getDoctorName(); // replaceCustomer = iBean.getCustomerName(); // replaceCustAddr1 = iBean.getCustomerAddr1(); // replaceBillNo = iBean.getBillNo(); // replaceBillDate = iBean.getPurchaseDate(); vat = iBean.getVat(); discount = iBean.getDiscount(); PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont)); table.addCell(c); c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont)); table.addCell(c); table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont))); totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice()); table.addCell(new PdfPCell(new Phrase( mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())), contentFont))); } } double grandTotal = 0.0; // Total PdfPCell c1 = new PdfPCell(new Phrase("Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt))); c1.setColspan(1); table.addCell(c1); // Vat c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double vatAmt = totalAmt * vat / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt))); c1.setColspan(1); table.addCell(c1); // Discount c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double discountAmt = totalAmt * discount / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt))); c1.setColspan(1); table.addCell(c1); // Grand Total c1 = new PdfPCell(new Phrase("Grand Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); grandTotal = (totalAmt + vatAmt - discountAmt); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal))); c1.setColspan(1); table.addCell(c1); document.add(table); }