-
-
Save mozerian/2ce4adfd164ed80cb3353ff7d7ae9edb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void createPaymentReport( List<Constants> paymentUsersList) throws DocumentException, FileNotFoundException{ | |
BaseColor colorWhite = WebColors.getRGBColor("#ffffff"); | |
BaseColor colorBlue = WebColors.getRGBColor("#056FAA"); | |
BaseColor grayColor = WebColors.getRGBColor("#425066"); | |
Font white = new Font(Font.FontFamily.HELVETICA, 15.0f, Font.BOLD, colorWhite); | |
FileOutputStream output = new FileOutputStream(pFile); | |
Document document = new Document(PageSize.A4); | |
PdfPTable table = new PdfPTable(new float[]{6, 25, 20, 20}); | |
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); | |
table.getDefaultCell().setFixedHeight(50); | |
table.setTotalWidth(PageSize.A4.getWidth()); | |
table.setWidthPercentage(100); | |
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); | |
Chunk noText = new Chunk("No.", white); | |
PdfPCell noCell = new PdfPCell(new Phrase(noText)); | |
noCell.setFixedHeight(50); | |
noCell.setHorizontalAlignment(Element.ALIGN_CENTER); | |
noCell.setVerticalAlignment(Element.ALIGN_CENTER); | |
Chunk nameText = new Chunk("First Name", white); | |
PdfPCell nameCell = new PdfPCell(new Phrase(nameText)); | |
nameCell.setFixedHeight(50); | |
nameCell.setHorizontalAlignment(Element.ALIGN_CENTER); | |
nameCell.setVerticalAlignment(Element.ALIGN_CENTER); | |
Chunk phoneText = new Chunk("Other Names", white); | |
PdfPCell phoneCell = new PdfPCell(new Phrase(phoneText)); | |
phoneCell.setFixedHeight(50); | |
phoneCell.setHorizontalAlignment(Element.ALIGN_CENTER); | |
phoneCell.setVerticalAlignment(Element.ALIGN_CENTER); | |
Chunk amountText = new Chunk("Phone Number", white); | |
PdfPCell amountCell = new PdfPCell(new Phrase(amountText)); | |
amountCell.setFixedHeight(50); | |
amountCell.setHorizontalAlignment(Element.ALIGN_CENTER); | |
amountCell.setVerticalAlignment(Element.ALIGN_CENTER); | |
Chunk footerText = new Chunk("Moses Njoroge - Copyright @ 2020"); | |
PdfPCell footCell = new PdfPCell(new Phrase(footerText)); | |
footCell.setFixedHeight(70); | |
footCell.setHorizontalAlignment(Element.ALIGN_CENTER); | |
footCell.setVerticalAlignment(Element.ALIGN_CENTER); | |
footCell.setColspan(4); | |
table.addCell(noCell); | |
table.addCell(nameCell); | |
table.addCell(phoneCell); | |
table.addCell(amountCell); | |
table.setHeaderRows(1); | |
PdfPCell[] cells = table.getRow(0).getCells(); | |
for (PdfPCell cell : cells) { | |
cell.setBackgroundColor(grayColor); | |
} | |
for (int i = 0; i < paymentUsersList.size(); i++) { | |
Constants pay = paymentUsersList.get(i); | |
String id = String.valueOf(i + 1); | |
String name = pay.getFirst_Name(); | |
String sname = pay.getOther_Name(); | |
String phone = pay.getPhone(); | |
table.addCell(id + ". "); | |
table.addCell(name); | |
table.addCell(sname); | |
table.addCell(phone); | |
} | |
PdfPTable footTable = new PdfPTable(new float[]{6, 25, 20, 20}); | |
footTable.setTotalWidth(PageSize.A4.getWidth()); | |
footTable.setWidthPercentage(100); | |
footTable.addCell(footCell); | |
PdfWriter.getInstance(document, output); | |
document.open(); | |
Font g = new Font(Font.FontFamily.HELVETICA, 25.0f, Font.NORMAL, grayColor); | |
document.add(new Paragraph(" How to generate real-time reports using Firebase\n\n", g)); | |
document.add(table); | |
document.add(footTable); | |
document.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment