List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareTable(List<? extends Column> visibleColumns) throws DocumentException { java.util.List<Integer> widths = new ArrayList<>(); for (Column column : visibleColumns) { widths.add(column.getColumnWidth()); }//from w ww. ja v a2 s . c o m PdfPTable table = new PdfPTable(widths.size()); table.setWidths(ArrayUtils.toPrimitive(widths.toArray(new Integer[widths.size()]))); table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(CELL_PADDING); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(2); table.setFooterRows(1); setTableHeader(table, visibleColumns); setBlankFooter(table, visibleColumns.size()); return table; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareRequisitionHeaderTable() throws DocumentException { int[] columnWidths = { 160, 160, 160, 160, 160 }; PdfPTable table = new PdfPTable(columnWidths.length); table.setWidths(columnWidths);/*from ww w . ja v a 2s.c o m*/ table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(10); table.getDefaultCell().setBorder(0); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(1); return table; }
From source file:org.restate.project.controller.PaymentReceiptController.java
License:Open Source License
@RequestMapping(method = RequestMethod.GET, value = "receipt.print") public void downloadDocument(HttpServletResponse response, @RequestParam(value = "id", required = false) Integer id) throws Exception { if (id == null) { return;//w ww . j a va 2 s . c om } // creation of the document with a certain size and certain margins // may want to use PageSize.LETTER instead // Document document = new Document(PageSize.A4, 50, 50, 50, 50); Document doc = new Document(); PdfWriter docWriter = null; DecimalFormat df = new DecimalFormat("0.00"); File tmpFile = File.createTempFile("paymentReceipt", ".pdf"); try { //special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(tmpFile)); //document header attributes doc.addAuthor("betterThanZero"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("MySampleCode.com"); doc.addTitle("Report with Column Headings"); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph Paragraph paragraph = new Paragraph("iText is a library that allows you to create and " + "manipulate PDF documents. It enables developers looking to enhance web and other " + "applications with dynamic PDF document generation and/or manipulation."); //specify column widths float[] columnWidths = { 1.5f, 2f, 5f, 2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(90f); //insert column headings insertCell(table, "Order No", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, "Account No", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "Account Name", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "Order Total", Element.ALIGN_RIGHT, 1, bfBold12); table.setHeaderRows(1); //insert an empty row insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12); //create section heading by cell merging insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12); double orderTotal, total = 0; //just some random data to fill for (int x = 1; x < 5; x++) { insertCell(table, "10010" + x, Element.ALIGN_RIGHT, 1, bf12); insertCell(table, "ABC00" + x, Element.ALIGN_LEFT, 1, bf12); insertCell(table, "This is Customer Number ABC00" + x, Element.ALIGN_LEFT, 1, bf12); orderTotal = Double.valueOf(df.format(Math.random() * 1000)); total = total + orderTotal; insertCell(table, df.format(orderTotal), Element.ALIGN_RIGHT, 1, bf12); } //merge the cells to create a footer for that section insertCell(table, "New York Total...", Element.ALIGN_RIGHT, 3, bfBold12); insertCell(table, df.format(total), Element.ALIGN_RIGHT, 1, bfBold12); //repeat the same as above to display another location insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12); insertCell(table, "California Orders ...", Element.ALIGN_LEFT, 4, bfBold12); orderTotal = 0; for (int x = 1; x < 7; x++) { insertCell(table, "20020" + x, Element.ALIGN_RIGHT, 1, bf12); insertCell(table, "XYZ00" + x, Element.ALIGN_LEFT, 1, bf12); insertCell(table, "This is Customer Number XYZ00" + x, Element.ALIGN_LEFT, 1, bf12); orderTotal = Double.valueOf(df.format(Math.random() * 1000)); total = total + orderTotal; insertCell(table, df.format(orderTotal), Element.ALIGN_RIGHT, 1, bf12); } insertCell(table, "California Total...", Element.ALIGN_RIGHT, 3, bfBold12); insertCell(table, df.format(total), Element.ALIGN_RIGHT, 1, bfBold12); //add the PDF table to the paragraph paragraph.add(table); // add the paragraph to the document doc.add(paragraph); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } response.setHeader("Content-disposition", "attachment; filename=" + "sampleDoc" + ".pdf"); response.setContentType("application/pdf"); OutputStream outputStream = response.getOutputStream(); FileInputStream fileInputStream = new FileInputStream(tmpFile); IOUtils.copy(fileInputStream, outputStream); fileInputStream.close(); outputStream.flush(); tmpFile.delete(); } }
From source file:org.sharegov.cirm.utils.PDFExportUtil.java
License:Apache License
private static void createTable(Section subCatPart, Json allData) throws DocumentException { Json metaData = allData.at("metaData"); PdfPTable table = null; PdfPCell c1 = null;/*from w w w. j av a 2 s . com*/ int columns = metaData.at("columns").asInteger(); table = new PdfPTable(columns); table.setWidthPercentage(100); if (columns == 9) { int[] widths = { 10, 20, 12, 12, 4, 6, 6, 8, 8 }; table.setWidths(widths); } else { int[] widths = { 10, 25, 12, 12, 4, 6, 6, 8 }; table.setWidths(widths); } // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); c1 = new PdfPCell(new Phrase(metaData.at("boid").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("type").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("fullAddress").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("city").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("zip").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("hasStatus").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("createdDate").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); c1 = new PdfPCell(new Phrase(metaData.at("lastActivityUpdatedDate").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); if (columns == 9) { c1 = new PdfPCell(new Phrase(metaData.at("gisColumn").asString(), smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c1); } table.setHeaderRows(1); List<Json> data = allData.at("data").asJsonList(); for (Json dataValue : data) { if (!dataValue.at("hasCaseNumber").asString().isEmpty()) c1 = new PdfPCell(new Phrase(dataValue.at("hasCaseNumber").asString(), smallFont)); else c1 = new PdfPCell(new Phrase(GenUtils.makeCaseNumber(dataValue.at("boid").asLong()), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("label").asString(), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("fullAddress").asString(), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("Street_Address_City").asString(), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("Zip_Code").asString(), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("hasStatus").asString(), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("hasDateCreated").asString(), smallFont)); table.addCell(c1); c1 = new PdfPCell(new Phrase(dataValue.at("lastActivityUpdatedDate").asString(), smallFont)); table.addCell(c1); if (columns == 9) { c1 = new PdfPCell(new Phrase(dataValue.at("gisColumn").asString(), smallFont)); table.addCell(c1); } } subCatPart.add(table); }
From source file:org.smap.sdal.managers.MiscPDFManager.java
License:Open Source License
public void createUsagePdf(Connection sd, OutputStream outputStream, String basePath, HttpServletResponse response, int o_id, int month, int year, String period, String org_name) { PreparedStatement pstmt = null; if (org_name == null) { org_name = "None"; }//from w w w. ja va 2 s. c o m try { String filename; // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/Library/Fonts/NotoSans-Regular.ttf", "notosans"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "default"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("default", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); filename = org_name + "_" + year + "_" + month + ".pdf"; /* * Get the usage results */ String sql = "SELECT users.id as id," + "users.ident as ident, " + "users.name as name, " + "(select count (*) from upload_event ue, subscriber_event se " + "where ue.ue_id = se.ue_id " + "and se.status = 'success' " + "and se.subscriber = 'results_db' " + "and extract(month from upload_time) = ? " // current month + "and extract(year from upload_time) = ? " // current year + "and ue.user_name = users.ident) as month, " + "(select count (*) from upload_event ue, subscriber_event se " + "where ue.ue_id = se.ue_id " + "and se.status = 'success' " + "and se.subscriber = 'results_db' " + "and ue.user_name = users.ident) as all_time " + "from users " + "where users.o_id = ? " + "and not users.temporary " + "order by users.ident;"; pstmt = sd.prepareStatement(sql); pstmt.setInt(1, month); pstmt.setInt(2, year); pstmt.setInt(3, o_id); log.info("Get Usage Data: " + pstmt.toString()); // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); setFilenameInResponse(filename, response); } /* * Get a template for the PDF report if it exists * The template name will be the same as the XLS form name but with an extension of pdf */ String stationaryName = basePath + File.separator + "misc" + File.separator + "UsageReportTemplate.pdf"; File stationaryFile = new File(stationaryName); ByteArrayOutputStream baos = null; ByteArrayOutputStream baos_s = null; PdfWriter writer = null; /* * Create document in two passes, the second pass adds the letter head */ // Create the underlying document as a byte array Document document = new Document(PageSize.A4); document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); if (stationaryFile.exists()) { baos = new ByteArrayOutputStream(); baos_s = new ByteArrayOutputStream(); writer = PdfWriter.getInstance(document, baos); } else { writer = PdfWriter.getInstance(document, outputStream); } writer.setInitialLeading(12); writer.setPageEvent(new PageSizer()); document.open(); // Write the usage data ResultSet resultSet = pstmt.executeQuery(); PdfPTable table = new PdfPTable(4); // Add the header row table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setBackgroundColor(VLG); table.addCell("User Id"); table.addCell("User Name"); table.addCell("Usage in Period"); table.addCell("All Time Usage"); table.setHeaderRows(1); // Add the user data int total = 0; int totalAllTime = 0; table.getDefaultCell().setBackgroundColor(null); while (resultSet.next()) { String ident = resultSet.getString("ident"); String name = resultSet.getString("name"); String monthUsage = resultSet.getString("month"); int monthUsageInt = resultSet.getInt("month"); String allTime = resultSet.getString("all_time"); int allTimeInt = resultSet.getInt("all_time"); table.addCell(ident); table.addCell(name); table.addCell(monthUsage); table.addCell(allTime); total += monthUsageInt; totalAllTime += allTimeInt; } // Add the totals table.getDefaultCell().setBackgroundColor(VLG); table.addCell("Totals: "); table.addCell(" "); table.addCell(String.valueOf(total)); table.addCell(String.valueOf(totalAllTime)); document.add(table); document.close(); if (stationaryFile.exists()) { // Step 2 - Populate the fields in the stationary PdfReader s_reader = new PdfReader(stationaryName); PdfStamper s_stamper = new PdfStamper(s_reader, baos_s); AcroFields pdfForm = s_stamper.getAcroFields(); Set<String> fields = pdfForm.getFields().keySet(); for (String key : fields) { log.info("Field: " + key); } pdfForm.setField("billing_period", period); pdfForm.setField("organisation", org_name); s_stamper.setFormFlattening(true); s_stamper.close(); // Step 3 - Apply the stationary to the underlying document PdfReader reader = new PdfReader(baos.toByteArray()); // Underlying document PdfReader f_reader = new PdfReader(baos_s.toByteArray()); // Filled in stationary PdfStamper stamper = new PdfStamper(reader, outputStream); PdfImportedPage letter1 = stamper.getImportedPage(f_reader, 1); int n = reader.getNumberOfPages(); PdfContentByte background; for (int i = 0; i < n; i++) { background = stamper.getUnderContent(i + 1); if (i == 0) { background.addTemplate(letter1, 0, 0); } } stamper.close(); reader.close(); } } catch (SQLException e) { log.log(Level.SEVERE, "SQL Error", e); } catch (Exception e) { log.log(Level.SEVERE, "Exception", e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (SQLException e) { } } }
From source file:org.smap.sdal.managers.MiscPDFManager.java
License:Open Source License
public void createTasksPdf(Connection sd, OutputStream outputStream, String basePath, HttpServletRequest request, HttpServletResponse response, int tgId) { try {/*from w ww . j av a 2 s.com*/ // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "default"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("default", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); /* * Get the tasks for this task group */ String urlprefix = request.getScheme() + "://" + request.getServerName(); TaskManager tm = new TaskManager(localisation, tz); TaskListGeoJson t = tm.getTasks(sd, urlprefix, 0, tgId, 0, false, 0, null, "all", 0, 0, "scheduled", "desc"); PdfWriter writer = null; String filename = "tasks.pdf"; // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); setFilenameInResponse(filename, response); } Document document = new Document(PageSize.A4); document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); writer = PdfWriter.getInstance(document, outputStream); writer.setInitialLeading(12); writer.setPageEvent(new PageSizer()); document.open(); PdfPTable table = new PdfPTable(4); // Add the header row table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setBackgroundColor(VLG); table.addCell("Form Name"); table.addCell("Task Name"); table.addCell("Status"); table.addCell("Assigned To"); table.setHeaderRows(1); // Add the task data table.getDefaultCell().setBackgroundColor(null); for (TaskFeature tf : t.features) { TaskProperties p = tf.properties; table.addCell(p.survey_name); table.addCell(p.name); table.addCell(p.status); table.addCell(p.assignee_name); } document.add(table); document.close(); } catch (SQLException e) { log.log(Level.SEVERE, "SQL Error", e); } catch (Exception e) { log.log(Level.SEVERE, "Exception", e); } }
From source file:org.techytax.report.helper.PdfReportHelper.java
License:Open Source License
private static void createTableHeader(Font headerFont, PdfPTable subTable) { Paragraph headerChunk = new Paragraph("Id", headerFont); PdfPCell cell = new PdfPCell(headerChunk); subTable.addCell(cell);//from ww w . j av a 2 s . c o m headerChunk = new Paragraph("Datum", headerFont); cell = new PdfPCell(headerChunk); subTable.addCell(cell); headerChunk = new Paragraph("Omschrijving", headerFont); cell = new PdfPCell(headerChunk); subTable.addCell(cell); headerChunk = new Paragraph("btw", headerFont); cell = new PdfPCell(headerChunk); subTable.addCell(cell); subTable.setHeaderRows(2); }
From source file:org.tvd.thptty.management.report.Report.java
private PdfPTable createSubjectPointTable() throws BadElementException { int countCell = cellTitles.length; PdfPTable table = new PdfPTable(countCell); table.setWidthPercentage(100);/*from ww w .ja v a 2 s . com*/ for (int i = 0; i < countCell; i++) { Phrase phrase = new Phrase(cellTitles[i], tahomaFont); PdfPCell cx = new PdfPCell(phrase); cx.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cx); } table.setHeaderRows(1); Phrase phrase = null; java.util.List<TYStudent> students = ActionUtil.getStudentsInClass(courses, tyClass.getClassId()); for (int i = 0; i < students.size(); i++) { //index phrase = new Phrase(String.valueOf(i + 1), tahomaFont); table.addCell(phrase); //student full name TYStudent student = students.get(i); student.setFullName(student.getStudentFirstName() + " " + student.getStudentLastName()); phrase = new Phrase(student.getFullName(), tahomaFont); table.addCell(phrase); //speak point float points[] = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.SPEAK_POINT, 1); String pointString = TYServiceUtil.floatsToPointString(points); phrase = new Phrase(pointString, smallBold); table.addCell(phrase); //15' point points = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.WRITE_POINT, 1); pointString = TYServiceUtil.floatsToPointString(points); phrase = new Phrase(pointString, smallBold); table.addCell(phrase); //45' point points = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.WRITE_POINT, 2); pointString = TYServiceUtil.floatsToPointString(points); phrase = new Phrase(pointString, smallBold); table.addCell(phrase); //90' point points = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.WRITE_POINT, 3); pointString = TYServiceUtil.floatsToPointString(points); phrase = new Phrase(pointString, smallBold); table.addCell(phrase); //avg point TYStudentPoint studentPointSubject = TYServiceUtil.getStudentAVGPointBySubject(courses, semester, student.getStudentId(), tySubject.getSubjectId()); float avgPointSubject = 0; if (studentPointSubject != null) avgPointSubject = TYServiceUtil.getCutFloat(studentPointSubject.getPoint(), 1); pointString = "" + avgPointSubject; phrase = new Phrase(pointString, smallBold); table.addCell(phrase); } float totalWidth = PageSize.A4.getWidth(); float columnWidths[] = { (float) (0.05 * totalWidth), (float) (0.35 * totalWidth), (float) (0.1 * totalWidth), (float) (0.2 * totalWidth), (float) (0.1 * totalWidth), (float) (0.1 * totalWidth), (float) (0.1 * totalWidth) }; try { table.setWidthPercentage(columnWidths, PageSize.A4); } catch (DocumentException e) { e.printStackTrace(); } return table; }
From source file:org.tvd.thptty.management.report.Report.java
private PdfPTable createStatisticsStudentPointTable() throws BadElementException { PdfPTable table = new PdfPTable(15); table.setWidthPercentage(100);//from w ww. ja va2s . c om for (int i = 0; i < 3; i++) { Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont); PdfPCell cx = new PdfPCell(phrase); cx.setHorizontalAlignment(Element.ALIGN_CENTER); cx.setVerticalAlignment(Element.ALIGN_MIDDLE); cx.setRowspan(3); table.addCell(cx); } for (int i = 3; i < 5; i++) { Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont); PdfPCell cx = new PdfPCell(phrase); cx.setHorizontalAlignment(Element.ALIGN_CENTER); cx.setVerticalAlignment(Element.ALIGN_MIDDLE); cx.setColspan(6); table.addCell(cx); } for (int i = 5; i < 11; i++) { Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont); PdfPCell cx = new PdfPCell(phrase); cx.setHorizontalAlignment(Element.ALIGN_CENTER); cx.setVerticalAlignment(Element.ALIGN_MIDDLE); cx.setColspan(2); table.addCell(cx); } for (int i = 11; i < 23; i++) { Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont); PdfPCell cx = new PdfPCell(phrase); cx.setHorizontalAlignment(Element.ALIGN_CENTER); cx.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cx); } table.setHeaderRows(3); Phrase phrase = null; for (int i = 0; rows != null && i < rows.size(); i++) { for (int k = 0; k < rows.get(i).getListCells().size(); k++) { phrase = new Phrase(rows.get(i).getListCells().get(k).getCellName(), tahomaSmallFont); PdfPCell cx = new PdfPCell(phrase); cx.setHorizontalAlignment(Element.ALIGN_CENTER); cx.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cx); } } float totalWidth = PageSize.A4.getWidth(); float columnWidths[] = new float[15]; for (int i = 0; i < columnWidths.length; i++) { columnWidths[i] = (float) (1.0 / 15) * totalWidth; } try { table.setWidthPercentage(columnWidths, PageSize.A4); } catch (DocumentException e) { e.printStackTrace(); } return table; }
From source file:org.tvd.thptty.management.util.Report.java
private PdfPTable createTable(Section subCatPart) throws BadElementException { int countCell = cellTitles.length; PdfPTable table = new PdfPTable(countCell); for (int i = 0; i < countCell; i++) { PdfPCell cx = new PdfPCell(new Phrase(cellTitles[i])); cx.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cx);/*w ww.jav a 2 s . c om*/ } table.setHeaderRows(1); java.util.List<TYStudent> students = ActionUtil.getStudentsInClass(courses, tyClass.getClassId()); for (int i = 0; i < students.size(); i++) { TYStudent student = students.get(i); student.setFullName(student.getStudentFirstName() + " " + student.getStudentLastName()); table.addCell(student.getFullName()); System.out.println("\n" + student.getFullName() + "\n"); float points[] = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.SPEAK_POINT, 1); String pointString = TYServiceUtil.floatsToPointString(points); table.addCell(pointString); points = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.WRITE_POINT, 1); pointString = TYServiceUtil.floatsToPointString(points); table.addCell(pointString); points = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.WRITE_POINT, 2); pointString = TYServiceUtil.floatsToPointString(points); table.addCell(pointString); points = TYServiceUtil.getPointStudentByPTPF(courses, semester, student.getStudentId(), tySubject.getSubjectId(), WebKeys.WRITE_POINT, 3); pointString = TYServiceUtil.floatsToPointString(points); table.addCell(pointString); java.util.List<TYStudentPoint> studentPointSubjects = TYServiceUtil.getStudentAVGPointBySubject(courses, semester, student.getStudentId(), tySubject.getSubjectId()); float avgPointSubject = 0; if (studentPointSubjects.size() > 0) avgPointSubject = TYServiceUtil.getCutFloat(studentPointSubjects.get(0).getPoint(), 2); pointString = "" + avgPointSubject; table.addCell(pointString); } subCatPart.add(table); return table; }