List of usage examples for com.itextpdf.text.pdf PdfPCell setPaddingBottom
public void setPaddingBottom(float paddingBottom)
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Builds the Header Cell used for every section of the document * * @param title the title for the cell/* w w w . ja v a 2s .c o m*/ * @param colspan the number of columns in the table it will be added to * @return a formatted PdfPCell ready to insert into a PdfPTable */ private PdfPCell getDefaultHeaderCell(String title, int colspan) { PdfPCell cell = new PdfPCell(); Paragraph titleParagraph = new Paragraph(title, new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK)); cell.addElement(titleParagraph); cell.setBorder(PdfPCell.NO_BORDER); cell.setColspan(colspan); cell.setBorderColorBottom(BaseColor.DARK_GRAY); cell.setBorderWidthBottom(1); cell.setPaddingBottom(5); return cell; }
From source file:fll.web.playoff.ScoresheetGenerator.java
License:Open Source License
public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException { // This creates our new PDF document and declares its orientation Document pdfDoc;/* w w w . j ava 2 s .com*/ if (orientationIsPortrait) { pdfDoc = new Document(PageSize.LETTER); // portrait } else { pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape } PdfWriter.getInstance(pdfDoc, out); // Measurements are always in points (72 per inch) // This sets up 1/2 inch margins side margins and 0.35in top and bottom // margins pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH); pdfDoc.open(); // Header cell with challenge title to add to both scoresheets final Paragraph titleParagraph = new Paragraph(); final Chunk titleChunk = new Chunk(m_pageTitle, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE)); titleParagraph.setAlignment(Element.ALIGN_CENTER); titleParagraph.add(titleChunk); titleParagraph.add(Chunk.NEWLINE); final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(), FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE)); titleParagraph.add(swVersionChunk); if (null != m_revision) { final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision, FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE)); titleParagraph.add(revisionChunk); } final PdfPCell head = new PdfPCell(); head.setColspan(2); head.setBorder(1); head.setPaddingTop(0); head.setPaddingBottom(3); head.setBackgroundColor(new BaseColor(64, 64, 64)); head.setVerticalAlignment(Element.ALIGN_TOP); head.addElement(titleParagraph); // Cells for score field, and 2nd check initials final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL); final PdfPCell desC = new PdfPCell(des); desC.setBorder(0); desC.setPaddingTop(9); desC.setPaddingRight(36); desC.setHorizontalAlignment(Element.ALIGN_RIGHT); final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL); final PdfPCell sciC = new PdfPCell(sci); sciC.setBorder(0); sciC.setPaddingTop(9); sciC.setPaddingRight(36); sciC.setHorizontalAlignment(Element.ALIGN_RIGHT); // Create a table with a grid cell for each scoresheet on the page PdfPTable wholePage = getTableForPage(orientationIsPortrait); wholePage.setWidthPercentage(100); for (int i = 0; i < m_numSheets; i++) { if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) { pdfDoc.newPage(); wholePage = getTableForPage(orientationIsPortrait); wholePage.setWidthPercentage(100); } // This table is a single score sheet final PdfPTable scoreSheet = new PdfPTable(2); // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER); scoreSheet.getDefaultCell().setPaddingRight(1); scoreSheet.getDefaultCell().setPaddingLeft(0); scoreSheet.addCell(head); final PdfPTable teamInfo = new PdfPTable(7); teamInfo.setWidthPercentage(100); teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f }); // Time label cell final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL); timeP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell()); timeLc.addElement(timeP); teamInfo.addCell(timeLc); // Time value cell final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL); final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell()); timeVc.addElement(timeV); teamInfo.addCell(timeVc); // Table label cell final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL); tblP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell()); tblLc.addElement(tblP); teamInfo.addCell(tblLc); // Table value cell final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL); final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell()); tblVc.addElement(tblV); teamInfo.addCell(tblVc); // Round number label cell final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL); rndP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell()); rndlc.addElement(rndP); teamInfo.addCell(rndlc); // Round number value cell final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL); final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell()); // rndVc.setColspan(2); rndVc.addElement(rndV); teamInfo.addCell(rndVc); final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell()); // temp1.setColspan(2); temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL)); teamInfo.addCell(temp1); // Team number label cell final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL); nbrP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell()); nbrlc.addElement(nbrP); teamInfo.addCell(nbrlc); // Team number value cell final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]), COURIER_10PT_NORMAL); final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell()); nbrVc.addElement(nbrV); teamInfo.addCell(nbrVc); // Team division label cell final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL); divP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell()); divlc.addElement(divP); divlc.setColspan(2); teamInfo.addCell(divlc); // Team division value cell final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL); final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell()); divVc.setColspan(2); divVc.addElement(divV); teamInfo.addCell(divVc); final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell()); // temp2.setColspan(2); temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL)); teamInfo.addCell(temp2); // Team name label cell final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL); nameP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell()); namelc.setColspan(2); namelc.addElement(nameP); teamInfo.addCell(namelc); // Team name value cell final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL); final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell()); nameVc.setColspan(5); nameVc.addElement(nameV); teamInfo.addCell(nameVc); // add team info cell to the team table final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell()); teamInfoCell.addElement(teamInfo); teamInfoCell.setColspan(2); scoreSheet.addCell(teamInfoCell); if (null != m_goalsTable) { final PdfPCell goalCell = new PdfPCell(m_goalsTable); goalCell.setBorder(0); goalCell.setPadding(0); goalCell.setColspan(2); scoreSheet.addCell(goalCell); } scoreSheet.addCell(desC); scoreSheet.addCell(sciC); if (null != m_copyright) { final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i); final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell()); copyrightC.addElement(copyright); copyrightC.setBorder(0); copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER); copyrightC.setColspan(2); scoreSheet.addCell(copyrightC); } // the cell in the whole page table that will contain the single score // sheet final PdfPCell scoresheetCell = new PdfPCell(scoreSheet); scoresheetCell.setBorder(0); scoresheetCell.setPadding(0); // Interior borders between scoresheets on a page if (!orientationIsPortrait) { if (i % 2 == 0) { scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH); } else { scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH); } } // Add the current scoresheet to the page wholePage.addCell(scoresheetCell); // Add the current table of scoresheets to the document if (orientationIsPortrait || (i % 2 != 0)) { pdfDoc.add(wholePage); } } // Add a blank cells to complete the table of the last page if (!orientationIsPortrait && m_numSheets % 2 != 0) { final PdfPCell blank = new PdfPCell(); blank.setBorder(0); wholePage.addCell(blank); pdfDoc.add(wholePage); } pdfDoc.close(); }
From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java
License:Apache License
private PdfPCell createHeaderCell(String content) { Paragraph paragraph = new Paragraph(); Font font = new Font(); font.setColor(BaseColor.WHITE);// w w w . j a v a 2 s. c om paragraph.setFont(font); paragraph.add(new Phrase(content)); PdfPCell cell = new PdfPCell(paragraph); cell.setPaddingBottom(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GRAY); return cell; }
From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java
License:Apache License
private List<Talk> createProgrammePages() throws DocumentException, IOException { List<Talk> talksToExplain = new ArrayList<>(); document.setPageSize(PageSize.A4.rotate()); Font font = new Font(); font.setStyle(Font.BOLD);//from w w w .ja va 2 s . c o m font.setSize(14); for (String date : service.getDates()) { Set<String> tracksInPage = new HashSet<>(); Map<String, Talk> precedentTalk = new HashMap<>(); PdfPTable table = createBeginningOfPage(font, date); for (String creneau : service.getCreneaux().get(date)) { // Nouvelle page 14h if (creneau.startsWith("14:00") && !tracksInPage.isEmpty()) { document.add(table); addLegend(tracksInPage); table = createBeginningOfPage(font, date); } PdfPCell cellCreneau = new PdfPCell(); cellCreneau.setPaddingBottom(10); Paragraph startTime = new Paragraph(creneau); startTime.setAlignment(Element.ALIGN_CENTER); cellCreneau.addElement(startTime); Paragraph endTime = new Paragraph(getEndTime(date, creneau)); endTime.setAlignment(Element.ALIGN_CENTER); cellCreneau.addElement(endTime); table.addCell(cellCreneau); for (String room : service.getRooms(date)) { PdfPCell cell = new PdfPCell(); cell.setPaddingBottom(10); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Talk talk = service.getTalkByDateAndCreneauxAndRoom(date, creneau, room); if (talk != null) { talksToExplain.add(talk); remplirCellWithTalk(cell, talk); cell.setRowspan(getRowSpan(date, talk)); precedentTalk.put(room, talk); tracksInPage.add(talk.getTrack()); table.addCell(cell); } else { talk = precedentTalk.get(room); if (!(talk != null && talk.getEnd().compareTo(creneau) > 0)) { table.addCell(cell); } } } } document.add(table); addLegend(tracksInPage); } return talksToExplain; }
From source file:fr.ybonnel.breizhcamppdf.RoomPdfRenderer.java
License:Apache License
private List<Talk> createProgrammePages() throws DocumentException, IOException { List<Talk> talksToExplain = new ArrayList<>(); document.setPageSize(PageSize.A4);//from www.j a v a 2s .c o m Font font = new Font(); font.setStyle(Font.BOLD); font.setSize(14); for (String date : service.getDates()) { for (String room : service.getRooms(date)) { Set<String> tracksInPage = new HashSet<>(); Map<String, Talk> precedentTalk = new HashMap<>(); PdfPTable table = createBeginningOfPage(font, date, room); for (String creneau : service.getCreneaux().get(date)) { PdfPCell cellCreneau = new PdfPCell(); cellCreneau.setPaddingBottom(10); Paragraph startTime = new Paragraph(creneau); startTime.setAlignment(Element.ALIGN_CENTER); cellCreneau.addElement(startTime); Paragraph endTime = new Paragraph(getEndTime(date, creneau)); endTime.setAlignment(Element.ALIGN_CENTER); cellCreneau.addElement(endTime); table.addCell(cellCreneau); PdfPCell cell = new PdfPCell(); cell.setPaddingBottom(10); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Talk talk = service.getTalkByDateAndCreneauxAndRoom(date, creneau, room); if (talk != null) { talksToExplain.add(talk); remplirCellWithTalk(cell, talk); cell.setRowspan(getRowSpan(date, talk)); precedentTalk.put(room, talk); tracksInPage.add(talk.getTrack()); table.addCell(cell); } else { talk = precedentTalk.get(room); if (!(talk != null && talk.getEnd().compareTo(creneau) > 0)) { table.addCell(cell); } } } document.add(table); addLegend(tracksInPage); } } return talksToExplain; }
From source file:fxml.test.PDFService.java
private PdfPCell nameCellHelper(String args) { PdfPCell cell = new PdfPCell(new Paragraph(args, font9)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingBottom(2.5f); return cell;//www.j av a 2s .c o m }
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 a va 2s .co 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 ww w .j a v a2s.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);/*from w w w. j av a 2 s . c o m*/ regCell.setPaddingBottom(3.85f); PdfPCell nameCell = getCellForString(student.getName(), 0, true, Element.ALIGN_MIDDLE, 0, font9, false); nameCell.setPaddingTop(1f); 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: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 {// ww w. ja v a2 s. c o m 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); } }