List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:bouttime.report.matkey.MatKeyReport.java
License:Open Source License
/** * Generate the Mat Key report.// w ww. j a v a2s.c o m * This is a color-coded report that maps the groups to a mat. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. */ public static boolean doReport(Dao dao) { if (!dao.isOpen()) { logger.warn("Cannot create report : DAO not open"); return false; } String matValues = dao.getMatValues(); if ((matValues == null) || matValues.isEmpty()) { JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame(); JOptionPane.showMessageDialog(mainFrame, "Mat values are not configured." + "\nSet the mat values in 'Edit -> Configuration'", "Mat Key Report error", JOptionPane.WARNING_MESSAGE); logger.warn("Cannot create report : mat values not configured"); return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Mat Key Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); int cols = 4; // Class, Div, Weight, Mat // create and add the table PdfPTable datatable = new PdfPTable(cols); //int colWidths[] = { 55, 15, 15, 15 }; // percentage //datatable.setWidths(colWidths); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("Class"); datatable.addCell("Div"); datatable.addCell("Weight"); datatable.addCell("Mat"); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); // Prepare the list of groups List<Group> groups = dao.getAllGroups(); Collections.sort(groups, new GroupClassDivWtSort()); // Prepare the list of mat values String[] mats = matValues.split(","); List<String> matList = new ArrayList<String>(); for (String m : mats) { matList.add(m.trim()); } for (Group g : groups) { String mat = g.getMat(); int idx = matList.indexOf(mat); datatable.getDefaultCell().setBackgroundColor(colorMap.get(idx)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(g.getClassification()); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(g.getAgeDivision()); datatable.addCell(g.getWeightClass()); datatable.addCell(g.getMat()); } datatable.setSpacingBefore(15f); // space between title and table document.add(datatable); } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.team.TeamReport.java
License:Open Source License
/** * Generate a summary report of the teams in the tournament. * This report lists the teams and the number of wresters on the team. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. *//*from w ww . j a v a2s . co m*/ public static boolean doSummary(Dao dao) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Team Summary Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); int cols = 2; // Team name and Total String classVals = dao.getClassificationValues(); String[] classes = null; if (classVals != null) { if (classVals.length() > 0) { classes = classVals.split(","); cols += classes.length; } } // create and add the table PdfPTable datatable = new PdfPTable(cols); //int colWidths[] = { 55, 15, 15, 15 }; // percentage //datatable.setWidths(colWidths); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("Team Name"); // Make a column for each classification value int[] classesTotals = null; if (classes != null) { for (String c : classes) { datatable.addCell(c.trim()); } classesTotals = new int[classes.length]; for (int i = 0; i < classesTotals.length; i++) { classesTotals[i] = 0; } } datatable.addCell("Total"); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); List<String> teams = dao.getTeams(); int total = 0; // total count of all wrestlers in this method int i = 0; for (String t : teams) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } List<Wrestler> wrestlers = dao.getWrestlersByTeam(t); int count = wrestlers.size(); int rowTotal = 0; total += count; datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(t); if (classes != null) { //for (String c : classes) { for (int idx = 0; idx < classes.length; idx++) { String c = classes[idx].trim(); List<Wrestler> wrestlers2 = dao.getWrestlersByTeamClass(t, c); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); int count2 = wrestlers2.size(); datatable.addCell(Integer.toString(count2)); classesTotals[idx] += count2; rowTotal += count2; } } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(Integer.toString(count)); // Check if there is an error in the counts. if ((classes != null) && (rowTotal != count)) { JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame(); JOptionPane.showMessageDialog(mainFrame, "There is an error" + " with the total count for team '" + t + "'.\n" + "This is " + "most likely due to an incorrect classification value\nfor " + "one or more wrestlers.", "Team count error", JOptionPane.WARNING_MESSAGE); } } // Add totals row datatable.getDefaultCell().setGrayFill(0.7f); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("Total"); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (classes != null) { for (int idx = 0; idx < classesTotals.length; idx++) { datatable.addCell(Integer.toString(classesTotals[idx])); } } datatable.addCell(Integer.toString(total)); datatable.setSpacingBefore(15f); document.add(datatable); } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.team.TeamReport.java
License:Open Source License
/** * Generate a detail report of the teams in the tournament. * This report includes the teams and all of the wrestlers on the team. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. *///w w w . j a v a 2s . c om public static boolean doDetail(Dao dao) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3); headerCell.setBorderWidth(2); List<String> teams = dao.getTeams(); for (String t : teams) { List<Wrestler> wrestlers = dao.getWrestlersByTeam(t); int count = wrestlers.size(); // create and add the table PdfPTable datatable = new PdfPTable(5); int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // The header has the team name and the number of entries headerCell.setPhrase(new Phrase(t, headerFont)); headerCell.setColspan(3); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont)); headerCell.setColspan(2); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); int i = 0; for (Wrestler w : wrestlers) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getClassification(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getAgeDivision(), detailFont)); datatable.addCell(new Phrase(w.getWeightClass(), detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.weighin.WeighInReport.java
License:Open Source License
/** * Generate a report of the entries in the tournament for weigh-in. * @param sections List of sections for the report. Each section will start * on a new page./* w ww .j a v a 2 s .c om*/ * @param headerString String to be used for the header of each page of the report. * @return True if the report was generated. */ public static boolean doReport(List<List<Wrestler>> sections, String headerString) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header if (headerString != null) { Paragraph p1 = new Paragraph( new Paragraph(headerString, FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); } Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); for (List<Wrestler> wrestlers : sections) { // create and add the table PdfPTable datatable = new PdfPTable(7); int colWidths[] = { 20, 20, 20, 10, 10, 10, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); int i = 0; for (Wrestler w : wrestlers) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getTeamName(), detailFont)); datatable.addCell(new Phrase(w.getClassification(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getAgeDivision(), detailFont)); datatable.addCell(new Phrase(w.getWeightClass(), detailFont)); datatable.addCell(new Phrase()); // actual weight } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); document.newPage(); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bsf.conn.DBMS.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("Personal Info", catFont); anchor.setName("Personal Info"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph(null, smallBold); Section subCatPart = catPart.addSection(subPara); // add a table subPara.setAlignment(Element.ALIGN_LEFT); createTable(subCatPart, info.personalInfo); // now add all this to the document document.add(catPart);/*from ww w. j av a2s .c om*/ // Next section anchor = new Anchor("Personal Information", catFont); anchor.setName("Personal Information"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Running Details", smallBold); subPara.setAlignment(Element.ALIGN_LEFT); subCatPart = catPart.addSection(subPara); // add a table addEmptyLine(subPara, 3); createTable(subCatPart, info.runningDetails); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Personal Information", catFont); anchor.setName("Personal Information"); // Thrd parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Leave Details", smallBold); subCatPart = catPart.addSection(subPara); // add a table addEmptyLine(subPara, 3); subPara.setAlignment(Element.ALIGN_LEFT); createTable(subCatPart, info.leaveDetails); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Family Information", catFont); anchor.setName("Family Information"); // Fourth parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph(null, smallBold); subCatPart = catPart.addSection(subPara); // add a table subPara.setAlignment(Element.ALIGN_LEFT); addEmptyLine(subPara, 3); createTable(subCatPart, info.familyInfo); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Course Information", catFont); anchor.setName("Course Information"); // Fifth parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph(null, smallBold); subCatPart = catPart.addSection(subPara); // add a table subPara.setAlignment(Element.ALIGN_LEFT); addEmptyLine(subPara, 3); createTable(subCatPart, info.courseDetails); // now add all this to the document document.add(catPart); }
From source file:BusinessLogic.Controller.HandleCertificate.java
public void downloadCertificate(ContractDAO contrDAO, CertificateDAO certificateDAO, UserDAO usDAO, HttpServletResponse response, int idUser, int option) throws DocumentException, IOException { User user = usDAO.searchByPkID(idUser); List<Certificate> certificateObject = certificateDAO.searchUserAproved(); List<Certificate> certificateReturn = new ArrayList<Certificate>(); if (certificateObject != null) { certificateReturn.clear();//from www. j a v a2 s . co m for (int i = 0; i < certificateObject.size(); i++) { if (certificateObject.get(i).getFkuserID().getPkID().equals(user.getPkID())) { certificateReturn.add(certificateObject.get(i)); } } } Contract contractObject = contrDAO.getUserContract(new User(user.getPkID())); Certificate cert = certificateReturn.get(option); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); Font fuente = new Font(); fuente.setStyle(Font.BOLD); fuente.setColor(BaseColor.BLACK); fuente.setFamily(Font.FontFamily.TIMES_ROMAN.toString()); fuente.setSize(15); Paragraph header = new Paragraph("\n\n\n\n\nEL DEPARTAMENTO DE GESTION HUMANA\n" + "DE TALENTO-HUMANO LTDA\n\n\n\n\n" + "CERTIFICA QUE:\n\n\n\n\n", fuente); header.setAlignment(Element.ALIGN_CENTER); Calendar fecha = new GregorianCalendar(); int annio = fecha.get(Calendar.YEAR); int mes = fecha.get(Calendar.MONTH) + 1; int dia = fecha.get(Calendar.DAY_OF_MONTH); Paragraph endtext = new Paragraph("\n\nSe expide la presente certificacion a solicitud" + " del interesado a la fecha de : " + dia + "/" + mes + "/" + annio + "\n\n\nCordialmente\n\n\nEdwin Alexander Bohorquez\nGERENTE GENERAL DE TALENTO-HUMANO LTDA"); endtext.setAlignment(Element.ALIGN_LEFT); String typeCertificate = ""; if (cert.getType().toLowerCase().equals("laboral")) { typeCertificate = "Laboral"; document.add(header); List<String> positionlist = new ArrayList<String>(); for (Position cargo : contractObject.getPositionSet()) { positionlist.add(cargo.getName()); } Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase() + " con cedula de ciudadania No." + user.getIdentifyCard() + ", trabaja en esta empresa" + " desde " + contractObject.getStartDate() + ", desempeandose actualmente como " + positionlist + " con una asignacion mensual de $" + contractObject.getSalary() + ".Su contrato de trabajo es a termino " + contractObject.getType() + "."); body.setAlignment(Element.ALIGN_JUSTIFIED_ALL); document.add(body); document.add(endtext); } else if (cert.getType().toLowerCase().equals("nmina")) { typeCertificate = "Nomina"; Paragraph Payroll_header = new Paragraph("DEPARTAMENTO DE CONTABILIDAD\n" + "TALENTO-HUMANO LTDA\n\n" + "LIQUIDACION DE NOMINA:\n" + "Nombre del empleado : " + user.getName() + " " + user.getLastname() + "\n" + "Cedula : " + user.getIdentifyCard() + "\n\n", fuente); Payroll_header.setAlignment(Element.ALIGN_CENTER); document.add(Payroll_header); double commissions = 10000; double extra_hours = 50000; double transportation_aid = 63600; double totalAccrued = contractObject.getSalary() + commissions + extra_hours + transportation_aid; PdfPTable basetable = new PdfPTable(2); PdfPCell headertable = new PdfPCell(new Paragraph("Tabla Base", fuente)); headertable.setColspan(2); basetable.addCell(headertable); PdfPCell cell1 = new PdfPCell(new Paragraph("Salario Basico : ")); PdfPCell cell2 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary()))); PdfPCell cell3 = new PdfPCell(new Paragraph("Comisiones : ")); PdfPCell cell4 = new PdfPCell(new Paragraph(String.valueOf(commissions))); PdfPCell cell5 = new PdfPCell(new Paragraph("Horas Extras : ")); PdfPCell cell6 = new PdfPCell(new Paragraph(String.valueOf(extra_hours))); PdfPCell cell7 = new PdfPCell(new Paragraph("Auxilio de transporte : ")); PdfPCell cell8 = new PdfPCell(new Paragraph(String.valueOf(transportation_aid))); PdfPCell ce9 = new PdfPCell(new Paragraph("Total Devengado : ")); PdfPCell ce10 = new PdfPCell(new Paragraph(" $ " + String.valueOf(totalAccrued))); basetable.setWidthPercentage(100F); basetable.setHorizontalAlignment(Element.ALIGN_CENTER); basetable.addCell(cell1); basetable.addCell(cell2); basetable.addCell(cell3); basetable.addCell(cell4); basetable.addCell(cell5); basetable.addCell(cell6); basetable.addCell(cell7); basetable.addCell(cell8); basetable.addCell(ce9); basetable.addCell(ce10); document.add(basetable); PdfPTable tableliquidation = new PdfPTable(2); PdfPCell title = new PdfPCell( new Paragraph("Liquidacion. Deducciones de nomina(Conceptos a cargo del empleado) ", fuente)); title.setColspan(2); tableliquidation.addCell(title); PdfPCell cell9 = new PdfPCell(new Paragraph("Salud (4%) : ")); PdfPCell cell10 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.04))); PdfPCell cell11 = new PdfPCell(new Paragraph("Pension (4%) : ")); PdfPCell cell12 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.04))); tableliquidation.setWidthPercentage(100F); tableliquidation.setHorizontalAlignment(Element.ALIGN_CENTER); tableliquidation.addCell(cell9); tableliquidation.addCell(cell10); tableliquidation.addCell(cell11); tableliquidation.addCell(cell12); document.add(tableliquidation); PdfPTable tablesocialSecurity = new PdfPTable(2); PdfPCell title2 = new PdfPCell(new Paragraph("Seguridad Social a cargo del empleador", fuente)); title2.setColspan(2); tablesocialSecurity.addCell(title2); PdfPCell cell13 = new PdfPCell(new Paragraph("Salud (8.5%) : ")); PdfPCell cell14 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.085))); PdfPCell cell15 = new PdfPCell(new Paragraph("Pension (12%) : ")); PdfPCell cell16 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.12))); PdfPCell cell17 = new PdfPCell(new Paragraph("A.R.P : ")); PdfPCell cell18 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.00522))); tablesocialSecurity.setWidthPercentage(100F); tablesocialSecurity.setHorizontalAlignment(Element.ALIGN_CENTER); tablesocialSecurity.addCell(cell13); tablesocialSecurity.addCell(cell14); tablesocialSecurity.addCell(cell15); tablesocialSecurity.addCell(cell16); tablesocialSecurity.addCell(cell17); tablesocialSecurity.addCell(cell18); document.add(tablesocialSecurity); PdfPTable social_benefits = new PdfPTable(2); PdfPCell title3 = new PdfPCell(new Paragraph("Prestaciones Sociales", fuente)); title3.setColspan(2); social_benefits.addCell(title3); PdfPCell cell19 = new PdfPCell(new Paragraph("Prima de servicios : ")); PdfPCell cell20 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833))); PdfPCell cell21 = new PdfPCell(new Paragraph("Cesantias : ")); PdfPCell cell22 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833))); PdfPCell cell23 = new PdfPCell(new Paragraph("Intereses sobre las cesantias : ")); PdfPCell cell24 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833 * 0.12))); PdfPCell cell25 = new PdfPCell(new Paragraph("Vacaciones : ")); PdfPCell cell26 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.0417))); social_benefits.setWidthPercentage(100F); social_benefits.setHorizontalAlignment(Element.ALIGN_CENTER); social_benefits.addCell(cell19); social_benefits.addCell(cell20); social_benefits.addCell(cell21); social_benefits.addCell(cell22); social_benefits.addCell(cell23); social_benefits.addCell(cell24); social_benefits.addCell(cell25); social_benefits.addCell(cell26); document.add(social_benefits); PdfPTable fiscal_contributions = new PdfPTable(2); PdfPCell title4 = new PdfPCell(new Paragraph("Aportes Parafiscales", fuente)); title4.setColspan(2); fiscal_contributions.addCell(title4); PdfPCell cell27 = new PdfPCell(new Paragraph("Cajas de compensacion familiar (4%) : ")); PdfPCell cell28 = new PdfPCell( new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.04))); PdfPCell cell29 = new PdfPCell(new Paragraph("I.CB.F (3%) : ")); PdfPCell cell30 = new PdfPCell( new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.03))); PdfPCell cell31 = new PdfPCell(new Paragraph("Sena (2%) : ")); PdfPCell cell32 = new PdfPCell( new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.02))); fiscal_contributions.setWidthPercentage(100F); fiscal_contributions.setHorizontalAlignment(Element.ALIGN_CENTER); fiscal_contributions.addCell(cell27); fiscal_contributions.addCell(cell28); fiscal_contributions.addCell(cell29); fiscal_contributions.addCell(cell30); fiscal_contributions.addCell(cell31); fiscal_contributions.addCell(cell32); document.add(fiscal_contributions); PdfPTable totalValue = new PdfPTable(2); PdfPCell title5 = new PdfPCell(new Paragraph("Neto a pagar al empleado", fuente)); title5.setColspan(2); totalValue.addCell(title5); PdfPCell cell33 = new PdfPCell(new Paragraph(" Total devengado - salud - pension")); cell33.setColspan(2); PdfPCell cell34 = new PdfPCell(new Paragraph( " $ " + String.valueOf(totalAccrued - contractObject.getSalary() * 0.08), fuente)); cell34.setColspan(2); totalValue.setWidthPercentage(100F); totalValue.setHorizontalAlignment(Element.ALIGN_CENTER); totalValue.addCell(cell33); totalValue.addCell(cell34); document.add(totalValue); document.add(endtext); } else if (cert.getType().toLowerCase().equals("salud")) { typeCertificate = "Salud"; document.add(header); Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase() + " con cedula de ciudadania No." + user.getIdentifyCard() + ", esta afiliado desde " + contractObject.getStartHealthDate() + " a la empresa de salud " + contractObject.getHealthEnterprise() + "."); body.setAlignment(Element.ALIGN_JUSTIFIED_ALL); document.add(body); document.add(endtext); } else if (cert.getType().toLowerCase().equals("pensin")) { typeCertificate = "Pension"; document.add(header); Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase() + " con cedula de ciudadania No." + user.getIdentifyCard() + ", esta afiliado a la empresa de pension " + contractObject.getPensionEnterprise() + ".La fecha de inicio de pension es " + contractObject.getStartPensionDate() + "."); body.setAlignment(Element.ALIGN_JUSTIFIED_ALL); document.add(body); document.add(endtext); } document.close(); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setContentType("application/octet-strem"); File f = new File("Certificado" + typeCertificate + ".pdf"); response.setHeader("Content-Disposition", "attachment;filename=" + f.getName()); response.setContentLength(baos.size()); System.out.println("Hasta aca crea el pdf bien"); OutputStream os = response.getOutputStream(); System.out.println("Ac'a ya deberia haber descargado"); baos.writeTo(os); os.flush(); os.close(); }
From source file:com.asae.controllers.BeanGestionRutinas.java
public void generarPdf() { Document document = new Document(); try {//from w w w . j a v a2s . co m File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf")); pdfFileName = file.getName(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD); URL url = FacesContext.getCurrentInstance().getExternalContext() .getResource("/resources/img/logo-unicauca-negro.png"); Image imgLogoUnicauca = Image.getInstance(url); imgLogoUnicauca.scaleAbsolute(118f, 131f); PdfPTable tableEncabezado = new PdfPTable(2); tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEncabezado.setWidthPercentage(100); tableEncabezado.setSpacingAfter(5); PdfPCell cell1 = new PdfPCell(imgLogoUnicauca); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa")); cell2.setBorder(Rectangle.NO_BORDER); cell2.setVerticalAlignment(Element.ALIGN_BOTTOM); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold)); cell3.setBorder(Rectangle.NO_BORDER); PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold)); cell4.setBorder(Rectangle.NO_BORDER); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); tableEncabezado.addCell(cell1); tableEncabezado.addCell(cell2); tableEncabezado.addCell(cell3); tableEncabezado.addCell(cell4); PdfPTable tableDatosUsuario = new PdfPTable(3); tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDatosUsuario.setWidthPercentage(100); tableDatosUsuario.setSpacingBefore(20); PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname() + " " + rutinaVisualizar.getIdusuario().getSecondname() + " " + rutinaVisualizar.getIdusuario().getFirstlastname() + " " + rutinaVisualizar.getIdusuario().getSecondlastname())); cell5.setBorder(Rectangle.NO_BORDER); PdfPCell cell6 = new PdfPCell(); cell6.setBorder(Rectangle.NO_BORDER); PdfPCell cell7 = new PdfPCell(); cell7.setBorder(Rectangle.NO_BORDER); tableDatosUsuario.addCell(cell5); tableDatosUsuario.addCell(cell6); tableDatosUsuario.addCell(cell7); PdfPTable tableFechas = new PdfPTable(3); tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableFechas.setWidthPercentage(100); tableFechas.setSpacingBefore(10); PdfPCell cell8 = new PdfPCell( new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio()))); cell8.setBorder(Rectangle.NO_BORDER); PdfPCell cell9 = new PdfPCell( new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin()))); cell9.setBorder(Rectangle.NO_BORDER); PdfPCell cell10 = new PdfPCell(); cell10.setBorder(Rectangle.NO_BORDER); tableFechas.addCell(cell8); tableFechas.addCell(cell9); tableFechas.addCell(cell10); PdfPTable tableMedidas = new PdfPTable(4); tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableMedidas.setWidthPercentage(100); tableMedidas.setSpacingBefore(10); Usuario usuAux = rutinaVisualizar.getIdusuario(); List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList(); Evaluacion evalAux; double peso = 0; if (lstEvalAux.size() > 0) { evalAux = lstEvalAux.get(lstEvalAux.size() - 1); peso = evalAux.getPeso().doubleValue(); } double estatura = 0; MedidasGenerales medGenAux = usuAux.getMedidasGenerales(); if (medGenAux != null) { estatura = medGenAux.getEstatura().doubleValue(); } PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso)); cell11.setBorder(Rectangle.NO_BORDER); PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura)); cell12.setBorder(Rectangle.NO_BORDER); double imc = 0; if (peso != 0 && estatura != 0) { imc = peso / Math.pow(estatura, 2); } PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc)); cell13.setBorder(Rectangle.NO_BORDER); PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina())); cell14.setBorder(Rectangle.NO_BORDER); tableMedidas.addCell(cell11); tableMedidas.addCell(cell12); tableMedidas.addCell(cell13); tableMedidas.addCell(cell14); PdfPTable tableDias = new PdfPTable(2); tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDias.setWidthPercentage(100); tableDias.setSpacingBefore(20); tableDias.setHorizontalAlignment(Element.ALIGN_LEFT); tableDias.setWidths(new int[] { 1, 9 }); List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList(); PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold)); PdfPCell cellCabezeraDia2 = new PdfPCell(); cellCabezeraDia2.setBorder(Rectangle.NO_BORDER); tableDias.addCell(cellCabezeraDia); tableDias.addCell(cellCabezeraDia2); for (Dia dia : lstDiasPDF) { PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString())); PdfPCell cellDia2 = new PdfPCell(); cellDia2.setBorder(Rectangle.NO_BORDER); List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList(); if (lstGMuscularPDF.size() > 0) { PdfPTable tableGMuscular = new PdfPTable(2); tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableGMuscular.setWidthPercentage(100); tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT); tableGMuscular.setWidths(new int[] { 1, 6 }); PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold)); cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); PdfPCell cellCabezeraGMuscular2 = new PdfPCell(); cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER); tableGMuscular.addCell(cellCabezeraGMuscular); tableGMuscular.addCell(cellCabezeraGMuscular2); int aux = 1; for (GrupoMuscular gMuscularFor : lstGMuscularPDF) { PdfPCell cellGMuscular = new PdfPCell( new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre())); cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); PdfPCell cellGMuscular2 = new PdfPCell(); cellGMuscular2.setBorder(Rectangle.NO_BORDER); List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList(); BaseColor myColor = WebColors.getRGBColor("#CCEEFF"); if (lstEjerciciosGMuscularPDF.size() > 0) { PdfPTable tableEjercicioGMsucular = new PdfPTable(5); tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEjercicioGMsucular.setWidthPercentage(100); tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold)); cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM.setLeading(20f, 0f); cellCabezeraEjercicioGM.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM); PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold)); cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM2.setLeading(20f, 0f); cellCabezeraEjercicioGM2.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2); PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold)); cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM3.setLeading(20f, 0f); cellCabezeraEjercicioGM3.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3); PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold)); cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM4.setLeading(20f, 0f); cellCabezeraEjercicioGM4.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4); PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold)); cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM5.setLeading(20f, 0f); cellCabezeraEjercicioGM5.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5); int aux2 = 1; for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) { PdfPCell cellEjercicioGM = new PdfPCell( new Paragraph(ejercicioGm.getEjercicio().getNombre())); cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM.setLeading(20f, 0f); PdfPCell cellEjercicioGM2 = new PdfPCell( new Paragraph(ejercicioGm.getNumeroSeries().toString())); cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM2.setLeading(20f, 0f); PdfPCell cellEjercicioGM3 = new PdfPCell( new Paragraph(ejercicioGm.getRepeticiones().toString())); cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM3.setLeading(20f, 0f); PdfPCell cellEjercicioGM4 = new PdfPCell( new Paragraph(ejercicioGm.getReceso().toString())); cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM4.setLeading(20f, 0f); PdfPCell cellEjercicioGM5 = new PdfPCell( new Paragraph(ejercicioGm.getPeso().toString())); cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM5.setLeading(20f, 0f); if (aux2 % 2 == 0) { cellEjercicioGM.setBackgroundColor(myColor); cellEjercicioGM2.setBackgroundColor(myColor); cellEjercicioGM3.setBackgroundColor(myColor); cellEjercicioGM4.setBackgroundColor(myColor); cellEjercicioGM5.setBackgroundColor(myColor); } tableEjercicioGMsucular.addCell(cellEjercicioGM); tableEjercicioGMsucular.addCell(cellEjercicioGM2); tableEjercicioGMsucular.addCell(cellEjercicioGM3); tableEjercicioGMsucular.addCell(cellEjercicioGM4); tableEjercicioGMsucular.addCell(cellEjercicioGM5); aux2++; } cellGMuscular2.addElement(tableEjercicioGMsucular); } tableGMuscular.addCell(cellGMuscular); tableGMuscular.addCell(cellGMuscular2); aux++; } cellDia2.addElement(tableGMuscular); } tableDias.addCell(cellDia); tableDias.addCell(cellDia2); } LineSeparator ls = new LineSeparator(); document.add(tableEncabezado); document.add(ls); document.add(tableDatosUsuario); document.add(tableFechas); document.add(tableMedidas); document.add(tableDias); document.close(); } catch (DocumentException | FileNotFoundException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * header ? footer /*from w w w. java 2s. co m*/ */ public void onEndPage(PdfWriter writer, Document document) { if (titleFlag) return; Font font = new Font(bfKorean, 9); PdfPTable hTable = new PdfPTable(1); PdfPTable ftable = new PdfPTable(3); try { hTable.setWidths(new int[] { 100 }); hTable.setTotalWidth(500); hTable.setLockedWidth(true); hTable.getDefaultCell().setFixedHeight(15); hTable.getDefaultCell().setBorder(Rectangle.BOTTOM); hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font)); hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent()); ftable.setWidths(new int[] { 100, 100, 100 }); ftable.setTotalWidth(500); ftable.setLockedWidth(true); ftable.getDefaultCell().setBorder(Rectangle.TOP); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font)); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (pagingFlag) ftable.addCell(new Phrase( MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())), font)); else ftable.addCell(""); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font)); ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent()); } catch (Exception de) { throw new ExceptionConverter(de); } }
From source file:com.automaster.autoview.server.servlet.TableHeader.java
/** * Fills out the total number of pages before the document is closed. * @see com.itextpdf.text.pdf.PdfPageEventHelper#onCloseDocument( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) *//*w w w . j a v a 2s . co m*/ public void onCloseDocument(PdfWriter writer, Document document) { ColumnText.showTextAligned(total, Element.ALIGN_LEFT, new Phrase(String.valueOf(writer.getPageNumber() - 1)), 2, 2, 0); }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private void writeDocument(Document document, File targetFile) { boolean frame = detailTabfolder.getSelectionIndex() == 1; try (FileOutputStream out = new FileOutputStream(targetFile)) { PdfWriter writer = PdfWriter.getInstance(document, out); document.open();/*w ww . j a v a 2 s . co m*/ writer.setPageEvent(new PdfPageEventHelper() { int pageNo = 0; com.itextpdf.text.Font ffont = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.DARK_GRAY); @Override public void onEndPage(PdfWriter w, Document d) { PdfContentByte cb = w.getDirectContent(); Phrase footer = new Phrase(String.valueOf(++pageNo), ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0); } }); String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText()); Paragraph p = new Paragraph(tit, FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(8); document.add(p); String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()), frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes); p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(14); document.add(p); p = new Paragraph(descriptionField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); p = new Paragraph(infoField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); IDbManager db = Core.getCore().getDbManager(); List<Wall> walls = current.getWall(); Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]); Arrays.sort(sortedWalls, new Comparator<Wall>() { public int compare(Wall o1, Wall o2) { return o1.getLocation().compareToIgnoreCase(o2.getLocation()); } }); for (Wall wall : sortedWalls) { p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(12); document.add(p); PdfPTable table = new PdfPTable(7); // table.setBorderWidth(1); // table.setBorderColor(new Color(224, 224, 224)); // table.setPadding(5); // table.setSpacing(0); table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 }); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT)); table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$ // table.endHeaders(); List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>(); for (String exhibitId : wall.getExhibit()) { ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId); if (exhibit != null) exhibits.add(exhibit); } Collections.sort(exhibits, new Comparator<ExhibitImpl>() { public int compare(ExhibitImpl e1, ExhibitImpl e2) { return ((Exhibit) e1).getX() - ((Exhibit) e2).getX(); } }); int no = 1; for (ExhibitImpl exhibit : exhibits) { int tara = computeTara(frame, exhibit); table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT)); table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT)); af.setMaximumFractionDigits(2); af.setMinimumFractionDigits(2); String x = af.format((exhibit.getX() - tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$ String y = af.format((exhibit.getY() + tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$ af.setMaximumFractionDigits(1); af.setMinimumFractionDigits(1); String h = af.format((exhibit.getHeight() + 2 * tara) / 10d); int width = exhibit.getWidth(); String w = af.format((width + 2 * tara) / 10d); table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$ AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset()); if (asset != null) { int pixels = asset.getWidth(); double dpi = pixels * 25.4d / width; table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT)); } else table.addCell(""); //$NON-NLS-1$ table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$ Element.ALIGN_LEFT)); } document.add(table); } document.close(); } catch (DocumentException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e); } catch (IOException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e); } }