List of usage examples for com.itextpdf.text.pdf PdfPCell setPaddingTop
public void setPaddingTop(float paddingTop)
From source file:fxml.test.PDFService.java
private PdfPTable createDocumentHeader() throws IOException, BadElementException { //start creating header for the document...... PdfPTable headerTable = new PdfPTable(3); headerTable.setHorizontalAlignment(Element.ALIGN_LEFT); try {//ww w .j a v a 2s . co m headerTable.setTotalWidth(new float[] { 57.5f, 531.5f, 183f }); headerTable.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } Image image = Image.getInstance(getClass().getClassLoader().getResource("img/sust.jpg")); image.scalePercent(42f); image.setAlignment(Element.ALIGN_LEFT); PdfPCell imageCell = new PdfPCell(image, false); imageCell.setPaddingTop(6); imageCell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(imageCell); //start info table..... PdfPTable infoTable = new PdfPTable(1); infoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); String universityText = "SHAHJALAL UNIVERSITY OF SCIENCE & TECHNOLOGY SYLHET, BANGLADESH"; String tabulationText = "TABULATION SHEET"; String deptText = inputs.get(0).trim(); String s1 = inputs.get(1).trim(); String s2 = inputs.get(2).trim(); String semesterText = ("B.Sc (Engg.) " + s1 + " SEMESTER EXAMINATION " + s2); String session = inputs.get(3).trim(); String date = inputs.get(4).trim(); String sessionDateText = ("SESSION:" + session + " EXAMINATION HELD IN: " + date); infoTable.addCell(getCellForHeaderString(universityText, 0, false, 0, Element.ALIGN_CENTER, font10, true)); infoTable.addCell(getCellForHeaderString(tabulationText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable.addCell(getCellForHeaderString(deptText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable.addCell(getCellForHeaderString(semesterText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable .addCell(getCellForHeaderString(sessionDateText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); //end info table..... PdfPCell infoCell = new PdfPCell(infoTable); infoCell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(infoCell); PdfPCell resultPublishDateCell = new PdfPCell( new Paragraph("Result Published On............................", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); resultPublishDateCell.setBorder(Rectangle.NO_BORDER); resultPublishDateCell.setVerticalAlignment(Element.ALIGN_MIDDLE); resultPublishDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(resultPublishDateCell); headerTable.setSpacingAfter(17.5f); // System.err.println("completed header table"); return headerTable; //end creating header for the document...... }
From source file:fxml.test.PDFService.java
public PdfPTable createFooter1() { //String[] names = new String[]{"Md. Eamin Rahman", "Md. Mujibur Rahman", "Md Masum", "Md. Saiful Islam", "Husne Ara Chowdhury", "Sabir Ismail"}; PdfPTable table = new PdfPTable(5); table.setHorizontalAlignment(Element.ALIGN_LEFT); try {//from www . j a v a 2 s . c om table.setTotalWidth(new float[] { 161f, 161f, 133f, 167f, 161f }); table.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } //table.setWidthPercentage(100); PdfPCell chairmanSIgnature = new PdfPCell(new Paragraph("Signature of the Chairman:", font9)); chairmanSIgnature.setBorder(Rectangle.NO_BORDER); chairmanSIgnature.setPaddingLeft(0f); chairmanSIgnature.setPaddingTop(5); table.addCell(chairmanSIgnature); PdfPCell underLine = new PdfPCell(new Paragraph("_______________________")); underLine.setBorder(Rectangle.NO_BORDER); table.addCell(underLine); PdfPCell blankColumn = new PdfPCell(new Paragraph(" ")); blankColumn.setBorder(Rectangle.NO_BORDER); table.addCell(blankColumn); Paragraph p = new Paragraph("Signature of The Controller of Examinations:", font9); p.setLeading(0, 1.3f); PdfPCell controllerSignature = new PdfPCell(); controllerSignature.addElement(p); controllerSignature.setBorder(Rectangle.NO_BORDER); table.addCell(controllerSignature); table.addCell(underLine); PdfPCell cell1 = new PdfPCell(new Paragraph(inputs.get(5).trim(), font9)); cell1.setPaddingTop(0f); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph(inputs.get(6).trim(), font9)); cell2.setPaddingTop(0f); cell2.setBorder(Rectangle.NO_BORDER); PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9)); nameColumn.setBorder(Rectangle.NO_BORDER); nameColumn.setPaddingLeft(0f); nameColumn.setPaddingTop(0f); PdfPCell nameColumn2 = new PdfPCell(new Paragraph("Name :", font9)); nameColumn2.setBorder(Rectangle.NO_BORDER); nameColumn2.setPaddingTop(0f); table.addCell(nameColumn); table.addCell(cell1); table.addCell(blankColumn); table.addCell(nameColumn2); table.addCell(cell2); table.setSpacingAfter(23.5f); return table; }
From source file:fxml.test.PDFService.java
public PdfPTable createFooter2() { PdfPTable table = new PdfPTable(8); table.setHorizontalAlignment(Element.ALIGN_LEFT); try {/*from w w w . ja v a 2s .c om*/ table.setTotalWidth(new float[] { 192f, 144f, 5f, 144f, 5f, 144f, 5f, 144f }); table.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell underLine = new PdfPCell(new Paragraph("_____________________")); underLine.setBorder(Rectangle.NO_BORDER); PdfPCell blankColumn = new PdfPCell(new Paragraph(" ")); blankColumn.setBorder(Rectangle.NO_BORDER); PdfPCell blankColumn2 = new PdfPCell(new Paragraph(" ")); blankColumn2.setBorder(Rectangle.BOTTOM); PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9)); nameColumn.setBorder(Rectangle.NO_BORDER); nameColumn.setPaddingLeft(0f); PdfPCell cell3 = new PdfPCell(new Paragraph(inputs.get(7).trim(), font9)); cell3.setPaddingRight(2); cell3.setBorder(Rectangle.TOP); PdfPCell cell4 = new PdfPCell(new Paragraph(inputs.get(8).trim(), font9)); cell4.setBorder(Rectangle.TOP); PdfPCell cell5 = new PdfPCell(new Paragraph(inputs.get(9).trim(), font9)); cell5.setBorder(Rectangle.TOP); PdfPCell cell6 = new PdfPCell(new Paragraph(inputs.get(10).trim(), font9)); cell6.setBorder(Rectangle.TOP); PdfPCell memberSignature = new PdfPCell(new Paragraph("Signature of the Members:", font9)); memberSignature.setPaddingLeft(0f); memberSignature.setBorder(Rectangle.NO_BORDER); table.addCell(memberSignature); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(nameColumn); table.addCell(cell3); table.addCell(blankColumn); table.addCell(cell4); table.addCell(blankColumn); table.addCell(cell5); table.addCell(blankColumn); table.addCell(cell6); PdfPCell tabulatorSignature = new PdfPCell(new Paragraph("Signature of the Tabulators:", font9)); tabulatorSignature.setPaddingLeft(0f); tabulatorSignature.setPaddingTop(13f); tabulatorSignature.setBorder(Rectangle.NO_BORDER); table.addCell(tabulatorSignature); table.addCell(blankColumn2); table.addCell(blankColumn); table.addCell(blankColumn2); table.addCell(blankColumn); table.addCell(blankColumn2); table.addCell(blankColumn); table.addCell(blankColumn2); return table; }
From source file:fxml.test.PDFService.java
public PdfPCell getCellForHeaderString(String args, int colSpan, boolean flag, int vertical, int horizontal, Font font, boolean wrap) { PdfPCell cell = new PdfPCell(new Paragraph(args, font)); if (colSpan != 0) { cell.setColspan(colSpan);/* w w w .j a v a2 s.c om*/ } cell.setVerticalAlignment(vertical); cell.setHorizontalAlignment(horizontal); cell.setPaddingTop(0.8f); if (!flag) { cell.setBorder(Rectangle.NO_BORDER); } if (wrap) { cell.setNoWrap(true); } return cell; }
From source file:fxml.test.PDFService.java
public PdfPTable createCourseInfo(Course course) { PdfPTable courseInfo = new PdfPTable(1); courseInfo.setWidthPercentage(100);//from w w w .j av a 2s. c o m courseInfo.addCell(getCellForString(course.getSemester(), Element.ALIGN_MIDDLE, false, 0, Element.ALIGN_CENTER, font7, false)); PdfPCell cell2 = getCellForString(course.getCourseCode(), Element.ALIGN_MIDDLE, false, 0, Element.ALIGN_CENTER, font9, true); cell2.setPaddingBottom(2.5f); cell2.setPaddingTop(3.4f); courseInfo.addCell(cell2); courseInfo.addCell(getCellForString(String.format("%.02f", course.getCredit()), 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false)); return courseInfo; }
From source file:fxml.test.PDFService.java
public PdfPTable createTableHeader(int start) { PdfPTable table = null;/*from w w w .j a va 2s. c o m*/ try { int colCount = 1; List<Float> columnsList = new ArrayList<>(); columnsList.add(57.5f); columnsList.add(159.4f); for (int i = start; i < list.size(); i++) { if (list.get(i) instanceof Course) { columnsList.add(44f); } else if (list.get(i).equals("Total Credit")) { columnsList.add(30f); } else if (list.get(i).equals("Total GPA")) { columnsList.add(30f); } else if (list.get(i).equals("Letter Grade")) { columnsList.add(30f); } else if (list.get(i).equals("Cumulative")) { columnsList.add(88f); } else { columnsList.add(66f); } if (colCount == 12) { break; } colCount++; } float[] columns = new float[columnsList.size()]; for (int i = 0; i < columnsList.size(); i++) { columns[i] = columnsList.get(i); } table = new PdfPTable(columns.length); System.err.println("table size :" + table.getNumberOfColumns()); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setTotalWidth(columns); table.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell regCell = getCellForString("Reg No.", 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); regCell.setPaddingTop(0f); table.addCell(regCell); PdfPCell nameCell = getNameCell(); nameCell.setPaddingBottom(2f); table.addCell(nameCell); int colCount = 1; for (int i = start; i < list.size(); i++) { if (list.get(i) instanceof Course) { Course course = (Course) list.get(i); PdfPCell cell3 = new PdfPCell(createCourseInfo(course)); cell3.setPaddingTop(1f); cell3.setPaddingBottom(2f); //cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell3); } else if (list.get(i).equals("Total Credit") || list.get(i).equals("Total GPA") || list.get(i).equals("Letter Grade")) { String str = (String) list.get(i); String s[] = str.split(" "); PdfPTable totalCredit = new PdfPTable(1); totalCredit.setSpacingBefore(12.5f); totalCredit.setWidthPercentage(100); totalCredit.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell1 = getCellForString(s[0], 0, false, 0, Element.ALIGN_CENTER, new Font(Font.FontFamily.TIMES_ROMAN, 10f), false); PdfPCell cell2 = getCellForString(s[1], 0, false, 0, Element.ALIGN_CENTER, new Font(Font.FontFamily.TIMES_ROMAN, 10f), false); totalCredit.addCell(cell1); totalCredit.addCell(cell2); PdfPCell grade = new PdfPCell(totalCredit); table.addCell(grade); } else if (list.get(i).equals("Cumulative")) { PdfPTable cumulative = new PdfPTable(1); // cumulative.setPaddingTop(count); cumulative.addCell(getCellForString("Cumulative", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); PdfPTable creditGpaGrade = new PdfPTable(3); creditGpaGrade.setTotalWidth(88f); creditGpaGrade.setLockedWidth(true); creditGpaGrade.addCell(getCellForString("Credit", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); creditGpaGrade.addCell(getCellForString("GPA", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); creditGpaGrade.addCell(getCellForString("Grade", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); PdfPTable p = new PdfPTable(1); PdfPCell cell1 = new PdfPCell(cumulative); cell1.setPaddingBottom(3f); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(creditGpaGrade); cell2.setBorder(Rectangle.NO_BORDER); p.addCell(cell1); p.addCell(cell2); table.addCell(p); } else { table.addCell(getCellForString((String) list.get(i), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, true)); } if (colCount == 12) { break; } colCount++; } return table; }
From source file:fxml.test.PDFService.java
private PdfPTable createTableBody(int studentStart, int start, PdfPTable table) { int studentCount = 1; for (int j = studentStart; j < studentList.size(); j++) { Student student = (Student) studentList.get(j); PdfPCell regCell = getCellForString(student.getRegNo(), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); regCell.setPaddingTop(2f); regCell.setPaddingBottom(3.85f); PdfPCell nameCell = getCellForString(student.getName(), 0, true, Element.ALIGN_MIDDLE, 0, font9, false); nameCell.setPaddingTop(1f);/*w w w.j a v a 2s. co m*/ nameCell.setPaddingBottom(3.85f); nameCell.setPaddingLeft(5f); table.addCell(regCell); table.addCell(nameCell); int colCount = 1; //Getting student regestered courses for current semester. Map<String, CourseReg> regesteredCourse = student.getRegesteredCourse(); for (int k = start; k < list.size(); k++) { //checking if its a instance of Course then we will print the Course details if (list.get(k) instanceof Course) { Course course = (Course) list.get(k); if (regesteredCourse.containsKey(course.getCourseCode())) { CourseReg courseReg = regesteredCourse.get(course.getCourseCode()); PdfPTable table1 = new PdfPTable(2); table1.setTotalWidth(44f); table1.setLockedWidth(true); PdfPCell cell1 = getCellForString(String.format("%.02f", courseReg.getGpa()), 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell1.setPaddingTop(1f); cell1.setPaddingBottom(4f); PdfPCell cell2 = getCellForString(courseReg.getLetterGrade(), 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell2.setPaddingTop(1f); cell2.setPaddingBottom(4f); table1.addCell(cell1); table1.addCell(cell2); PdfPCell cell3 = new PdfPCell(table1); cell3.setPaddingTop(0f); cell3.setPaddingBottom(0f); table.addCell(cell3); } else { table.addCell(new PdfPCell()); } } //End checking if its a instance of Course then we will print the Course details else if (list.get(k).equals("Total Credit")) { PdfPCell creditCell = getCellForString(String.valueOf(student.getTotalCredit()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); creditCell.setPaddingTop(1f); creditCell.setPaddingBottom(4f); table.addCell(creditCell); } else if (list.get(k).equals("Total GPA")) { PdfPCell gpaCell = getCellForString(String.format("%.02f", student.getGpa()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); gpaCell.setPaddingTop(1f); gpaCell.setPaddingBottom(4f); table.addCell(gpaCell); } else if (list.get(k).equals("Letter Grade")) { PdfPCell gradeCell = getCellForString(student.getLetterGrade(), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); gradeCell.setPaddingTop(1f); gradeCell.setPaddingBottom(4f); table.addCell(gradeCell); } else if (list.get(k).equals("Cumulative")) { PdfPTable table1 = new PdfPTable(3); table1.setTotalWidth(88f); table1.setLockedWidth(true); PdfPCell cell1 = getCellForString(String.format("%.02f", student.getCumulativeCredit()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell1.setPaddingTop(1f); cell1.setPaddingBottom(4f); PdfPCell cell2 = getCellForString(String.format("%.02f", student.getCumulativeGpa()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell2.setPaddingTop(1f); cell2.setPaddingBottom(4f); PdfPCell cell3 = getCellForString(student.getCumulativeLetterGrade(), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell3.setPaddingTop(1f); cell3.setPaddingBottom(4f); table1.addCell(cell1); table1.addCell(cell2); table1.addCell(cell3); PdfPCell cell4 = new PdfPCell(table1); cell4.setPaddingTop(0f); cell4.setPaddingBottom(0f); table.addCell(cell4); } else { table.addCell(new PdfPCell()); } if (colCount == 12) { break; } colCount++; } if (studentCount == 15) { break; } studentCount++; } return table; }
From source file:generators.InvoiceGenerator.java
/** * Generate Invoice pdf file/*from w w w. j a v a 2 s . co m*/ * * @param order the order * @throws DocumentException the document exception * @throws IOException the io exception */ public void generate(Order order) throws DocumentException, IOException { Date invoiceDate = order.getDate(); SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM YYYY"); // User guest = order.getGuest(); User guest = new UserDAO().get(order.getUserId()); guest.setOrder(order); System.out.println("invoice generator orderID: " + order.getId()); Document document = new Document(); Font defaultFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); System.out.println(System.getProperty("user.dir")); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(System.getProperty("user.dir") + "/src/main/java/nl/ipsen3/invoice/" + new SimpleDateFormat("dd-MM-yyyy").format(invoiceDate) + " - " + order.getId() + ".pdf")); document.setMargins(30, 30, 30, 65); writer.setPageEvent(new InvoiceEventListener()); document.open(); Paragraph header = new Paragraph("Lionsclub Oegstgeest/Warmond", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); header.setAlignment(Element.ALIGN_CENTER); document.add(header); AddressDAO addressDAO = new AddressDAO(); Address userAddress = addressDAO.get(guest.getAddressId()); Paragraph address = new Paragraph(guest.getFirstName() + " " + guest.getPrefixLastName() + " " + guest.getLastName() + "\n" + userAddress.getStreet() + " " + userAddress.getHouseNumber() + "\n" + userAddress.getZipCode() + " " + userAddress.getCity(), defaultFont); address.setSpacingBefore(35); address.setSpacingAfter(25); address.setLeading(15); document.add(address); Paragraph invoiceDetails = new Paragraph("Factuurdatum: " + sdf.format(invoiceDate) + "\n" + "FactuurNummer: " + order.getId() + " \n" + "Debiteurennummer: " + guest.getId(), defaultFont); invoiceDetails.setSpacingAfter(15); invoiceDetails.setLeading(15); document.add(invoiceDetails); Paragraph subject = new Paragraph("Betreft: Onderwerp factuur", defaultFont); subject.setSpacingAfter(30); document.add(subject); PdfPTable orderTable = new PdfPTable(10); PdfPCell wineCell = new PdfPCell(new Paragraph("Wijn", defaultFont)); wineCell.setColspan(5); wineCell.setBorder(Rectangle.BOTTOM); orderTable.getDefaultCell().setPaddingBottom(10); orderTable.getDefaultCell().setBorder(Rectangle.BOTTOM); ; orderTable.addCell(new Paragraph("Code", defaultFont)); orderTable.addCell(new Paragraph("Aantal", defaultFont)); orderTable.addCell(wineCell); orderTable.addCell(new Paragraph("Jaar", defaultFont)); orderTable.addCell(new Paragraph("Per Fles", defaultFont)); orderTable.addCell(new Paragraph("Bedrag", defaultFont)); orderTable.getDefaultCell().setPaddingBottom(0); orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); wineCell.setBorder(Rectangle.NO_BORDER); NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.GERMANY); for (WineOrder wineOrder : order.getWineOrders()) { orderTable.addCell(new Paragraph("" + wineOrder.getWine().getId(), defaultFont)); orderTable.addCell(new Paragraph("" + wineOrder.getAmount(), defaultFont)); wineCell.setPhrase(new Phrase(wineOrder.getWine().getName(), defaultFont)); orderTable.addCell(wineCell); orderTable.addCell(new Paragraph("" + wineOrder.getWine().getYear(), defaultFont)); orderTable.addCell(new Paragraph( " " + numberFormat.format(wineOrder.getWine().getPrice()).replace(" ", ""), defaultFont)); orderTable.addCell(new Paragraph(" " + numberFormat .format(wineOrder.getAmount() * wineOrder.getWine().getPrice()).replace(" ", ""), defaultFont)); orderTable.completeRow(); } orderTable.addCell(" "); orderTable.completeRow(); Font totalFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); PdfPCell totalAmount = new PdfPCell( new Paragraph(" " + numberFormat.format(order.getTotalAmount()).replace(" ", ""), totalFont)); totalAmount.setBorder(Rectangle.TOP); totalAmount.setPaddingTop(10); PdfPCell totalCell = new PdfPCell(new Paragraph("Totaal", totalFont)); totalCell.setPaddingTop(10); totalCell.setBorder(Rectangle.NO_BORDER); orderTable.addCell(totalCell); PdfPCell fillerCell = new PdfPCell(new Paragraph("")); fillerCell.setColspan(8); fillerCell.setBorder(Rectangle.NO_BORDER); orderTable.addCell(fillerCell); orderTable.addCell(totalAmount); orderTable.setSpacingBefore(15); orderTable.setSpacingAfter(30); orderTable.setWidthPercentage(95); orderTable.setHorizontalAlignment(Element.ALIGN_CENTER); document.add(orderTable); Paragraph retrievalDetails = new Paragraph( "Wij verzoeken u vriendelijk het totaalbedrag binnen 7 dagen na factuurdatum over te maken op bankrekening <bankAccountNr> t.n.v <bankAccountName> onder vermelding van het factuurnummer", defaultFont); retrievalDetails.setLeading(15); retrievalDetails.setSpacingAfter(20); document.add(retrievalDetails); // document.add(new Paragraph("U kunt uw wijnen ophalen op " + sdf.format(invoiceDate) , defaultFont)); // document.add(new Paragraph("Adres:", defaultFont)); // // PdfPTable addressTable = new PdfPTable(1); // addressTable.setSpacingBefore(5); // addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // addressTable.getDefaultCell().setPaddingLeft(35); // MerchantService merchantService = new MerchantService(); // Merchant merchant = merchantService.find(merchantService.all().get(0).getId()); // addressTable.addCell(new Paragraph(merchant.getName(), defaultFont)); // addressTable.addCell(new Paragraph(merchant.getAddress().getStreet() // + " " + merchant.getAddress().getHouseNumber(), defaultFont)); // addressTable.addCell(new Paragraph(merchant.getAddress().getZipCode() + " " + // merchant.getAddress().getCity(), defaultFont)); // addressTable.setHorizontalAlignment(Element.ALIGN_LEFT); // document.add(addressTable); document.close(); System.out.println( "Succesfully generated IPSEN2.invoice: " + order.getId() + " on Date: " + sdf.format(invoiceDate)); }
From source file:ManagementPackage.ServiceEnd.java
private void txtDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoneActionPerformed // TODO add your handling code here: Document doc = new Document(); try {/*from w w w . ja va 2 s . com*/ long time = new Date().getTime(); TransNo = "" + time; PdfWriter.getInstance(doc, new FileOutputStream("Invoices\\Invoices" + time + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(4); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Invoice/Money Receipt\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("Transaction No: " + time, FontFactory.getFont(null, 10))); cell3.setColspan(2); cell3.setPaddingBottom(10); cell3.setPaddingTop(10); cell3.setBorder(2); cell3.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell3); PdfPCell cell4 = new PdfPCell( new Paragraph("Date: " + formatedDateTime, FontFactory.getFont(null, 10))); cell4.setColspan(3); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); //table.addCell("Sl No"); table.addCell("Product Name"); table.addCell("Rate"); table.addCell("Qty"); table.addCell("Amount (TK)"); String query = "select product_name, rate, qty, amount from temp_trans WHERE trans_by = '" + user + "'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { //String sl_no = rs.getString("sl_no"); String product_name = rs.getString("product_name"); String rate = rs.getString("rate"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); //table.addCell(sl_no); table.addCell(product_name); table.addCell(rate); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph(txtTotal.getText())); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph(txtAdjust.getText())); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Billed By: " + user)); celltxtTotalPaid.setColspan(2); //celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid0 = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid0.setColspan(1); celltxtTotalPaid0.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid0); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph(txtTotalPaid.getText())); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); savePermanently(); clearTempTable(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Invoices\\Invoices" + time + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed // TODO add your handling code here: totalAdjustment = 0;//from www . j a v a 2 s. c om totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Daily" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Daily Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date = '" + formatedDate + "'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Daily" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }