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; }
private PdfPTable generateLineItemTable(List<ExpenseItem> listItems, String monthName) { PdfPTable table = new PdfPTable(4); DecimalFormat df = new DecimalFormat("0.00"); double total = 0; for (ExpenseItem lineItem : listItems) { if (lineItem.getPrice() >= 100 && lineItem.getPrice() < 500) { table.addCell(PDFCellStyles.listBlueCell(lineItem.getDate())); table.addCell(PDFCellStyles.listBlueCell(lineItem.getItem())); table.addCell(PDFCellStyles.listBlueCell(lineItem.getDescription())); table.addCell(PDFCellStyles.listBlueCell("Rs." + df.format(lineItem.getPrice()))); } else if (lineItem.getPrice() > 500) { table.addCell(PDFCellStyles.listRedCell(lineItem.getDate())); table.addCell(PDFCellStyles.listRedCell(lineItem.getItem())); table.addCell(PDFCellStyles.listRedCell(lineItem.getDescription())); table.addCell(PDFCellStyles.listRedCell("Rs." + df.format(lineItem.getPrice()))); } else { table.addCell(PDFCellStyles.listCell(lineItem.getDate())); table.addCell(PDFCellStyles.listCell(lineItem.getItem())); table.addCell(PDFCellStyles.listCell(lineItem.getDescription())); table.addCell(PDFCellStyles.listCell("Rs." + df.format(lineItem.getPrice()))); } total += lineItem.getPrice(); } table.addCell(PDFCellStyles.totalStyle("")); table.addCell(PDFCellStyles.totalStyle("Total Expense")); table.addCell(PDFCellStyles.totalStyle(monthName)); table.addCell(PDFCellStyles.totalStyle("Rs." + df.format(total))); return table; }