List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
From source file:Tables.Printer.java
public void salarySuspension(TableView supIssTab, TableColumn name, TableColumn amount, TableColumn reason, TableColumn susDate, TableColumn status, long total) { String title = "Salary Suspension"; try {//from w w w . j av a 2 s . co m // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\staff\\suspension " + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(PageSize.A4, 10, 10, 5, 10); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 6f, 3f, 8f, 3f, 2f }; PdfPTable table = new PdfPTable(columnWidths); //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, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Reason", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Status", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amount.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, reason.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, susDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, status.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void staffSalaryPayments(TableView supIssTab, TableColumn name, TableColumn monthlySalary, TableColumn salaryPaid, TableColumn payDate, long total) { String fileName = "staffPayment"; String title = "Staff Payment History"; try {/*from ww w .j a v a 2s . com*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\staff\\pay " + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 6f, 4f, 4f, 4f }; PdfPTable table = new PdfPTable(columnWidths); //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, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Monthly Salary ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Salary Paid", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Payment Date", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, monthlySalary.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, salaryPaid.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, payDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void supCust_PayDebt(TableView supPayTab, TableColumn name, TableColumn debtPayment, TableColumn paymtDate, long total, String title, String fileName) { try {//from w w w . ja v a2s.c om // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\default" + app + ".pdf"; if (fileName == "SupplierDebtPayment") { file = "\\Documents\\NjieAB_receipts\\supplier\\pay " + app + ".pdf"; } else if (fileName == "CustumerDebtPayment") { file = "\\Documents\\NjieAB_receipts\\custumer\\pay " + app + ".pdf"; } else if (fileName == "StaffBalSalaryt") { file = "\\Documents\\NjieAB_receipts\\staff\\balance " + app + ".pdf"; } System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f, 3f }; PdfPTable table = new PdfPTable(columnWidths); //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); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings if (fileName == "SupplierDebtPayment") { insertTableHeading(table, "Supplier Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date Issued", Element.ALIGN_MIDDLE, 1, bfBold12); } else if (fileName == "CustumerDebtPayment") { insertTableHeading(table, "Custumer Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date Issued", Element.ALIGN_MIDDLE, 1, bfBold12); } else if (fileName == "StaffBalSalaryt") { insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Branch", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Balance Amount", Element.ALIGN_MIDDLE, 1, bfBold12); } table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supPayTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, debtPayment.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, paymtDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 2, bfBold12); insertCell(table, "", Element.ALIGN_RIGHT, 3, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void footer(Document doc) throws DocumentException { Paragraph paragraph = new Paragraph("Njieforbi Bakery, Cameroon Buea"); doc.add(paragraph);//from w w w.jav a 2 s . c o m dNow = new Date(); String prodDate = "Created on the " + datOnly.format(dNow) + " at " + timOnly.format(dNow); ////////////////// PdfPTable timeOfProduction = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Phrase(prodDate.trim(), smallFooter)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBorder(0); if (prodDate.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } timeOfProduction.addCell(cell); doc.add(timeOfProduction); Dialogs.create().title("Printing Complete").masthead("Printing process complete.") .message("Patient while the file open to see your printout.").showInformation(); }
From source file:Tables.Printer.java
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align);/*from w ww.j a v a2s.co m*/ //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table table.addCell(cell); }
From source file:Tables.Printer.java
private void insertTableHeading(PdfPTable table, String text, int align, int colspan, Font font) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align);/*from www .ja v a2 s . co m*/ //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); }
From source file:Tables.PrinterClass.java
/**************************************** * heading ends//from ww w . jav a2 s. c o m */ private void insertTableHeading(PdfPTable table, String text, int align, int colspan, Font font) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align); //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); }
From source file:Tables.PrinterClass.java
public void footer(Document doc) throws DocumentException { Paragraph paragraph = new Paragraph("@" + this.companyName); doc.add(paragraph);// www .j ava2 s. co m dNow = new Date(); String prodDate; prodDate = "Created on the " + dateOnly.format(dNow) + " at " + timeOnly.format(dNow); ////////////////// PdfPTable timeOfProduction = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Phrase(prodDate.trim(), smallFooter)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBorder(0); if (prodDate.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } timeOfProduction.addCell(cell); doc.add(timeOfProduction); try { Image img = Image.getInstance(this.companyLogo); img.scaleAbsolute(20f, 20f); img.setAbsolutePosition((PageSize.A4.getWidth() - img.getScaledWidth()), (PageSize.A4.getHeight() - img.getScaledHeight())); //place the image at the bottom right position img.setAlt("Unity Systems"); } catch (Exception ex) { } }
From source file:Tables.PrinterClass.java
/** * heading ends//from ww w. j a v a2 s .co m * @param tabId * @param col1 * @param col2 * @param tHeading * @param fileName * @param tTitle */ public void print(TableView tabId, TableColumn col1, TableColumn col2, String fileName, String tTitle, String[] tHeading) { dNow = new Date(); System.out.println("printing with 2 cols"); try { String completeFileName = this.saveDir + fileName + this.datForFile.format(dNow) + ".pdf"; completeFileName = System.getProperties().getProperty("user.home") + completeFileName; fs = new FileOutputStream(completeFileName); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea Document doc = new Document(PageSize.A4, 20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 5f, 5f }; PdfPTable table = new PdfPTable(columnWidths); table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); makeCompanyHeading(doc); doc.add(cell); System.out.println(doc.leftMargin()); for (String tHeading1 : tHeading) { insertTableHeading(table, tHeading1, Element.ALIGN_CENTER, 1, this.tHeadingFont); } table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < tabId.getItems().size(); i++) { insertCell(table, col1.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont); insertCell(table, col2.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont); } doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); Dialogs.create().title("Printing complete").masthead("The printing process was completed succesfully") .message("See : " + completeFileName).showInformation(); } catch (Exception sd) { sd.printStackTrace(); Dialogs.create().title("Printer Error").masthead("Errro In Printing File") .message("There was an error while trying to print. ").showError(); } finally { } }
From source file:Tables.PrinterClass.java
/** * heading ends/*from w w w . j a va2s . co m*/ * @param tabId * @param col1 * @param col2 * @param tHeading * @param fileName * @param tTitle */ public void print(TableView tabId, TableColumn col1, TableColumn col2, TableColumn col3, String fileName, String tTitle, String[] tHeading) { dNow = new Date(); System.out.println("printing with 2 cols"); try { String completeFileName = this.saveDir + fileName + this.datForFile.format(dNow) + ".pdf"; completeFileName = System.getProperties().getProperty("user.home") + completeFileName; fs = new FileOutputStream(completeFileName); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea Document doc = new Document(PageSize.A4, 20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 4f, 4f }; PdfPTable table = new PdfPTable(columnWidths); table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); makeCompanyHeading(doc); doc.add(cell); System.out.println(doc.leftMargin()); for (String tHeading1 : tHeading) { insertTableHeading(table, tHeading1, Element.ALIGN_CENTER, 1, this.tHeadingFont); } table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < tabId.getItems().size(); i++) { insertCell(table, col1.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont); insertCell(table, col2.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont); insertCell(table, col3.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont); } doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); Dialogs.create().title("Printing complete").masthead("The printing process was completed succesfully") .message("See : " + completeFileName).showInformation(); } catch (Exception sd) { sd.printStackTrace(); Dialogs.create().title("Printer Error").masthead("Errro In Printing File") .message("There was an error while trying to print. ").showError(); } finally { } }