List of usage examples for com.itextpdf.text Paragraph Paragraph
public Paragraph(float leading, String string)
Paragraph
with a certain String
and a certain leading. From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java
@Override public void crear(File file) { try {/*ww w .j a va 2 s . c o m*/ document = new Document(PageSize.A4, 50f, 50f, 100f, 220f); file.createNewFile(); writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); writer.setPageEvent(event); document.newPage(); Paragraph p = new Paragraph("RELACIN DE PRODUCTOS PARA DESTRUCCIN", FUENTE_TITULO_APTO); p.setAlignment(Element.ALIGN_CENTER); document.add(p); document.add(configurarInformacion()); PdfPTable table = crearTabla(); agregarProductos(table); document.add(table); document.close(); } catch (IOException | DocumentException ex) { Log.print(ex); } Object[] options = { "Abrir PDF", "No" }; int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options, options[0]); if (open == JOptionPane.YES_OPTION) { try { Desktop.getDesktop().open(file); } catch (IOException ex) { Log.print("No se encontr la ruta"); JOptionPane.showMessageDialog(null, "Error en el archivo"); } } }
From source file:com.dexter.fms.mbean.ReportsMBean.java
@SuppressWarnings("deprecation") private PdfPTable exportPDFTable(int type) { int numberOfColumns = 0; PdfPTable pdfTable = null;// w w w . j av a2s .c o m switch (type) { case 1: // all users report { numberOfColumns = 7; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("User name", font)); pdfTable.addCell(new Paragraph("Full name", font)); pdfTable.addCell(new Paragraph("Email", font)); pdfTable.addCell(new Paragraph("Department", font)); pdfTable.addCell(new Paragraph("Region", font)); pdfTable.addCell(new Paragraph("Phone", font)); pdfTable.addCell(new Paragraph("Position", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getAllUsers() != null) { for (PartnerUser e : getAllUsers()) { pdfTable.addCell(new Paragraph(e.getUsername(), font)); pdfTable.addCell(new Paragraph( e.getPersonel().getFirstname() + " " + e.getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getPersonel().getEmail(), font)); pdfTable.addCell(new Paragraph( (e.getPersonel().getDepartment() != null) ? e.getPersonel().getDepartment().getName() : "N/A", font)); pdfTable.addCell(new Paragraph( (e.getPersonel().getRegion() != null) ? e.getPersonel().getRegion().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getPersonel().getPhone(), font)); pdfTable.addCell(new Paragraph(e.getPersonel().getPosition(), font)); } } break; } case 2: // due driver's license { numberOfColumns = 6; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Full Name", font)); pdfTable.addCell(new Paragraph("Dept", font)); pdfTable.addCell(new Paragraph("Region", font)); pdfTable.addCell(new Paragraph("Phone", font)); pdfTable.addCell(new Paragraph("Position", font)); pdfTable.addCell(new Paragraph("License Due Date", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getDueDriversLic() != null) { for (DriverLicense e : getDueDriversLic()) { pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getFirstname() + " " + e.getDriver().getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getDepartment() != null ? e.getDriver().getPersonel().getDepartment().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getRegion() != null ? e.getDriver().getPersonel().getRegion().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPhone(), font)); pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPosition(), font)); pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font)); } } break; } case 3: // accidents { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Accident Date", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Driver", font)); pdfTable.addCell(new Paragraph("Driver Comment", font)); pdfTable.addCell(new Paragraph("Police Officer", font)); pdfTable.addCell(new Paragraph("Police Station", font)); pdfTable.addCell(new Paragraph("Police Comment", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getVehicleAccidents() != null) { for (VehicleAccident e : getVehicleAccidents()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font)); pdfTable.addCell(new Paragraph(e.getDriver_name(), font)); pdfTable.addCell(new Paragraph(e.getDriverComment(), font)); pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font)); pdfTable.addCell(new Paragraph(e.getPoliceStation(), font)); pdfTable.addCell(new Paragraph(e.getPoliceComment(), font)); } } break; } case 4: // vehicles by brand { numberOfColumns = 4; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Make", font)); pdfTable.addCell(new Paragraph("Model", font)); pdfTable.addCell(new Paragraph("Year", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getVehiclesByBrand() != null) { for (Vehicle e : getVehiclesByBrand()) { pdfTable.addCell(new Paragraph(e.getModel().getMaker().getName(), font)); pdfTable.addCell(new Paragraph(e.getModel().getName(), font)); pdfTable.addCell(new Paragraph(e.getModel().getYear(), font)); pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font)); } } break; } case 5: // routine maintenance { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Requester", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Start Date", font)); pdfTable.addCell(new Paragraph("Initial Cost", font)); pdfTable.addCell(new Paragraph("Status", font)); pdfTable.addCell(new Paragraph("Close Date", font)); pdfTable.addCell(new Paragraph("Final Cost", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getRmaints() != null) { for (VehicleRoutineMaintenance e : getRmaints()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " " + e.getCreatedBy().getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getDescription(), font)); pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getInitial_amount().toPlainString(), font)); pdfTable.addCell(new Paragraph(e.getStatus(), font)); pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getClosed_amount().toPlainString(), font)); } } break; } case 6: // ad hoc maintenance { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Requester", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Start Date", font)); pdfTable.addCell(new Paragraph("Initial Cost", font)); pdfTable.addCell(new Paragraph("Status", font)); pdfTable.addCell(new Paragraph("Close Date", font)); pdfTable.addCell(new Paragraph("Final Cost", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getAdhocmaints() != null) { for (VehicleAdHocMaintenance e : getAdhocmaints()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " " + e.getCreatedBy().getPersonel().getLastname(), font)); pdfTable.addCell(new Paragraph(e.getDescription(), font)); pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getInitial_cost().toPlainString(), font)); pdfTable.addCell(new Paragraph(e.getStatus(), font)); pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getClosed_cost().toPlainString(), font)); } } break; } case 7: // active accidents { numberOfColumns = 8; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Accident Date", font)); pdfTable.addCell(new Paragraph("Description", font)); pdfTable.addCell(new Paragraph("Driver Name", font)); pdfTable.addCell(new Paragraph("Driver Comment", font)); pdfTable.addCell(new Paragraph("Police Name", font)); pdfTable.addCell(new Paragraph("Station Name", font)); pdfTable.addCell(new Paragraph("Police Comment", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getActiveAccidents() != null) { for (VehicleAccident e : getActiveAccidents()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font)); pdfTable.addCell(new Paragraph(e.getDriver_name(), font)); pdfTable.addCell(new Paragraph(e.getDriverComment(), font)); pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font)); pdfTable.addCell(new Paragraph(e.getPoliceStation(), font)); pdfTable.addCell(new Paragraph(e.getPoliceComment(), font)); } } break; } case 8: // coporate trips { numberOfColumns = 9; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 6, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Requester", font)); pdfTable.addCell(new Paragraph("Department", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Departure Location", font)); pdfTable.addCell(new Paragraph("Arrival Location", font)); pdfTable.addCell(new Paragraph("Departure Date and Time", font)); pdfTable.addCell(new Paragraph("Est. Arrival Date and Time", font)); pdfTable.addCell(new Paragraph("Act. Arrival Date and Time", font)); pdfTable.addCell(new Paragraph("Status", font)); font = new Font(helvetica, 6, Font.NORMAL); if (getCorTrips() != null) { for (CorporateTrip e : getCorTrips()) { pdfTable.addCell( new Paragraph(e.getStaff().getFirstname() + " " + e.getStaff().getLastname(), font)); pdfTable.addCell(new Paragraph( (e.getStaff().getDepartment() != null) ? e.getStaff().getDepartment().getName() : "N/A", font)); pdfTable.addCell(new Paragraph( e.getVehicle() != null ? e.getVehicle().getRegistrationNo() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getDepartureLocation(), font)); pdfTable.addCell(new Paragraph(e.getArrivalLocation(), font)); pdfTable.addCell(new Paragraph(e.getDepartureDateTime().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getEstimatedArrivalDateTime().toLocaleString(), font)); pdfTable.addCell(new Paragraph( e.getCompleteRequestDateTime() != null ? e.getCompleteRequestDateTime().toLocaleString() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getTripStatus(), font)); } } break; } case 9: // expense report { numberOfColumns = 4; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Type", font)); pdfTable.addCell(new Paragraph("Date", font)); pdfTable.addCell(new Paragraph("Amount", font)); pdfTable.addCell(new Paragraph("Detail", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getExpenses() != null) { for (Expense e : getExpenses()) { pdfTable.addCell(new Paragraph(e.getType().getName(), font)); pdfTable.addCell(new Paragraph(e.getExpense_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph("" + e.getAmount(), font)); pdfTable.addCell(new Paragraph(e.getRemarks(), font)); } } break; } case 10: // vehicle ages { numberOfColumns = 6; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Make", font)); pdfTable.addCell(new Paragraph("Model", font)); pdfTable.addCell(new Paragraph("Year", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Date of Purchase", font)); pdfTable.addCell(new Paragraph("Age (in years)", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getVehiclesAges() != null) { for (Vehicle e : getVehiclesAges()) { pdfTable.addCell(new Paragraph( e.getModel().getMaker() != null ? e.getModel().getMaker().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getYear() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font)); pdfTable.addCell(new Paragraph( e.getPurchaseDate() != null ? e.getPurchaseDate().toLocaleString() : "N/A", font)); pdfTable.addCell(new Paragraph("" + e.getAge(), font)); } } break; } case 11: // vehicle fuelings { numberOfColumns = 5; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Date", font)); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Litres", font)); pdfTable.addCell(new Paragraph("Amount", font)); pdfTable.addCell(new Paragraph("Source", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getFuelings() != null) { for (VehicleFueling e : getFuelings()) { pdfTable.addCell(new Paragraph(e.getCaptured_dt().toLocaleString(), font)); pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph("" + e.getLitres(), font)); pdfTable.addCell(new Paragraph("" + e.getAmt(), font)); pdfTable.addCell(new Paragraph(e.getSource(), font)); } } break; } case 12: // due vehicle licenses { numberOfColumns = 5; pdfTable = new PdfPTable(numberOfColumns); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Reg No.", font)); pdfTable.addCell(new Paragraph("Fleet", font)); pdfTable.addCell(new Paragraph("Make", font)); pdfTable.addCell(new Paragraph("Model", font)); pdfTable.addCell(new Paragraph("License Due Date", font)); font = new Font(helvetica, 8, Font.NORMAL); if (getDueVehicleLicenses() != null) { for (VehicleLicense e : getDueVehicleLicenses()) { pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font)); pdfTable.addCell(new Paragraph(e.getVehicle().getFleet().getName(), font)); pdfTable.addCell(new Paragraph( e.getVehicle().getModel() != null ? e.getVehicle().getModel().getMaker().getName() : "N/A", font)); pdfTable.addCell(new Paragraph( e.getVehicle().getModel() != null ? e.getVehicle().getModel().getName() : "N/A", font)); pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font)); } } break; } } pdfTable.setWidthPercentage(100); return pdfTable; }
From source file:com.docdoku.server.extras.TitleBlockGenerator.java
License:Open Source License
protected void generateHeader(Paragraph preface, ResourceBundle bundle) { // Title + description preface.add(new Paragraph(title, BOLD_18)); addEmptyLine(preface, 1);//from w ww . j a v a 2 s . com if (!description.isEmpty()) { preface.add(new Paragraph(description, NORMAL_12)); } // Separator LineSeparator separator = new LineSeparator(); preface.add(separator); addEmptyLine(preface, 1); }
From source file:com.docdoku.server.extras.TitleBlockGenerator.java
License:Open Source License
protected void generateTable(Paragraph preface, ResourceBundle bundle) { // Author + date PdfPTable table = new PdfPTable(2); table.setWidthPercentage(TABLE_PERCENT_WIDTH); PdfPCell cell;/*from w ww. j a v a 2 s . c o m*/ cell = new PdfPCell(new Phrase(authorName, NORMAL_12)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(creationDate, NORMAL_12)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); preface.add(table); addEmptyLine(preface, 1); preface.add(new Paragraph(bundle.getString("iteration"), BOLD_12)); addEmptyLine(preface, 1); PdfPTable iterationTable = new PdfPTable(5); iterationTable.setWidthPercentage(TABLE_PERCENT_WIDTH); // Table header cell = new PdfPCell(new Phrase(bundle.getString("iteration.version"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.iteration"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.date"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.author"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.Notes"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); // Table body cell = new PdfPCell(new Phrase(version, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(currentIteration, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(iterationDate, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(authorName, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(revisionNote, NORMAL_12)); iterationTable.addCell(cell); preface.add(iterationTable); }
From source file:com.docdoku.server.extras.TitleBlockGenerator.java
License:Open Source License
public void generateAttribute(Paragraph preface, ResourceBundle bundle) { // Table title preface.add(new Paragraph(bundle.getString("attributes"), BOLD_12)); addEmptyLine(preface, 1);/*from w ww.j ava 2 s . com*/ PdfPTable attributesTable = new PdfPTable(2); attributesTable.setWidthPercentage(100f); // Table head PdfPCell cell = new PdfPCell(new Phrase(bundle.getString("attributes.name"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); attributesTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("attributes.value"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); attributesTable.addCell(cell); // Table body for (InstanceAttribute attr : instanceAttributes) { cell = new PdfPCell(new Phrase(attr.getName(), NORMAL_12)); attributesTable.addCell(cell); Object value = attr.getValue(); cell = new PdfPCell(new Phrase(value != null ? String.valueOf(value) : "", NORMAL_12)); attributesTable.addCell(cell); } preface.add(attributesTable); }
From source file:com.docdoku.server.extras.TitleBlockGenerator.java
License:Open Source License
private void generateLyfeCycleState(Paragraph preface, ResourceBundle bundle) { // Table title preface.add(new Paragraph(bundle.getString("lifecycle") + " : " + lifeCycleState, BOLD_12)); addEmptyLine(preface, 1);//from w w w . jav a 2 s. c o m PdfPTable lifeCycleTable = new PdfPTable(5); lifeCycleTable.setWidthPercentage(100f); PdfPCell cell; for (Activity activity : workflow.getActivities()) { boolean headerRendered = false; for (Task task : activity.getTasks()) { if (task.isApproved() || task.isRejected()) { if (!headerRendered) { // Table head cell = new PdfPCell(new Phrase(activity.getLifeCycleState(), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(5); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("lifecycle.task"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("lifecycle.date"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("lifecycle.author"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("lifecycle.comments"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("lifecycle.signature"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); lifeCycleTable.addCell(cell); headerRendered = true; } // Table body cell = new PdfPCell(new Phrase(task.getTitle(), NORMAL_12)); lifeCycleTable.addCell(cell); SimpleDateFormat simpleFormat = new SimpleDateFormat(bundle.getString("date.format")); cell = new PdfPCell(new Phrase(simpleFormat.format(task.getClosureDate()), NORMAL_12)); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(task.getWorker().getName(), NORMAL_12)); lifeCycleTable.addCell(cell); cell = new PdfPCell(new Phrase(task.getClosureComment(), NORMAL_12)); lifeCycleTable.addCell(cell); if (task.getSignature() != null) { try { byte[] imageByte; int indexOfFirstComma = task.getSignature().indexOf(","); String base64 = task.getSignature().substring(indexOfFirstComma + 1, task.getSignature().length()); imageByte = DatatypeConverter.parseBase64Binary(base64); Image image = Image.getInstance(imageByte); image.setCompressionLevel(Image.ORIGINAL_NONE); image.scaleToFit(SIGNATURE_SIZE_W, SIGNATURE_SIZE_H); cell = new PdfPCell(image); lifeCycleTable.addCell(cell); } catch (Exception e) { cell = new PdfPCell(new Phrase(bundle.getString("signature.error"), NORMAL_12)); lifeCycleTable.addCell(cell); } } else { cell = new PdfPCell(new Phrase("")); lifeCycleTable.addCell(cell); } } } } preface.add(lifeCycleTable); }
From source file:com.documents.services.LicenseRegistrationFormServiceImpl.java
License:Open Source License
@Override public void createPdf(List<String> infoList, String filePath) throws IOException, DocumentException { /**//from w ww. jav a 2s. c o m * We insert here the path where we can find the JSON */ BufferedReader br = new BufferedReader( new FileReader("src\\main\\resources\\documentsAdditionalText.json")); List<String> jsonKeys = new ArrayList<>(); String jsonString; Paragraph emptyLines; jsonString = PdfUtility.initiliazeJson(br); JSONObject obj = new JSONObject(jsonString); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head1")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head2")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head3")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head4")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("introduction")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text1") + infoList.get(0)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text2") + infoList.get(1)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text3") + infoList.get(2)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text4") + infoList.get(3)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text5") + infoList.get(4)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text6") + infoList.get(5)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text7") + infoList.get(6)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text8") + infoList.get(7)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text9") + infoList.get(8)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text10") + infoList.get(9)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text11") + infoList.get(10)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text12") + infoList.get(11)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text13")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("final")); /** * Generate the document with the content extracted from Json */ Document document = PdfUtility.initializeDocument(filePath); String paragraphElem = PdfUtility.concatenateString(jsonKeys.get(0), jsonKeys.get(1)); Paragraph paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(2)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(3)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); emptyLines = PdfUtility.addEmptyLine(3); document.add(emptyLines); PdfUtility.addTitle(document, jsonKeys.get(4)); emptyLines = PdfUtility.addEmptyLine(2); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(5)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(6)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(7)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(8), jsonKeys.get(9)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(10), jsonKeys.get(11)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(12), jsonKeys.get(13)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(7); document.add(emptyLines); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(14)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(3); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(15)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(7); document.add(emptyLines); document.add(emptyLines); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(16), jsonKeys.get(17)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(7); document.add(emptyLines); document.add(emptyLines); PdfUtility.addFooter(document, jsonKeys.get(18)); PdfUtility.finalizeDocument(document); }
From source file:com.ftt.gui.FrameFormation.java
private void pdf1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf1ActionPerformed if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText()) || dateclot.getDate() == null || dateov.getDate() == null) { JOptionPane.showMessageDialog(this, "Vrifier les champs !"); } else {/*w w w . ja va2 s . c o m*/ SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy"); String val1 = lieux.getText(); String val2 = formateur.format(dateov.getDate()); String val3 = formateur.format(dateclot.getDate()); String val4 = combocible.getSelectedItem().toString(); String val5 = nomf.getText(); String val6 = descriptionf.getText(); Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf")); document.open(); com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png"); document.add(image); document.add(new Paragraph("Liste des formations", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD))); document.add(new Paragraph(formateur.format(new Date()))); String val322 = formateur.format(new Date()); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("formations")); cell.setColspan(4); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); table.addCell("Nom formation"); table.addCell(val5); table.addCell(cell); table.addCell("Description"); table.addCell(val6); table.addCell(cell); table.addCell("Lieux"); table.addCell(val1); table.addCell("Date d'ouverture"); table.addCell(val2); table.addCell("Date de cloture"); table.addCell(val3); table.addCell("Cible"); table.addCell(val4); document.add(table); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Responsable des formations")); document.add(new Paragraph("Federation Tunisenne de Tennis")); document.close(); JOptionPane.showMessageDialog(null, "Rapport Enregistrer"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:com.ftt.gui.FrameFormation.java
private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed FormationDAO fd = new FormationDAO(); ArrayList<Formation> formations = (ArrayList<Formation>) fd.select(); SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy"); Document document = new Document(); try {/*from w w w .j a v a 2 s. c o m*/ PdfWriter.getInstance(document, new FileOutputStream("rapport_formations.pdf")); document.open(); com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png"); document.add(image); document.add(new Paragraph("Liste des formations", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD))); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); for (int i = 0; i < formations.size(); i++) { document.add(new Paragraph(" ")); int val = formations.get(i).getId(); String val1 = formations.get(i).getLieux(); String val2 = formations.get(i).getDateOuverture(); String val3 = formations.get(i).getDateCloture(); String val4 = formations.get(i).getCible(); String val5 = formations.get(i).getNom(); String val6 = formations.get(i).getDescription(); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("formation " + val)); cell.setColspan(4); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); table.addCell("Nom formation"); table.addCell(val5); table.addCell("Description"); table.addCell(val6); table.addCell("Lieux"); table.addCell(val1); table.addCell("Date d'ouverture"); table.addCell(val2); table.addCell("Date de cloture"); table.addCell(val3); table.addCell("Cible"); table.addCell(val4); document.add(table); } document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Responsable des formations")); document.add(new Paragraph("Federation Tunisenne de Tennis")); document.close(); JOptionPane.showMessageDialog(null, "Rapport Enregistrer"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:com.ftt.gui.FrameJoueur.java
private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed JoueurDAO fd = new JoueurDAO(); ArrayList<Joueur> joueurs = (ArrayList<Joueur>) fd.select_trie_par_club(); SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy"); Document document = new Document(); try {//from w ww. j a v a2 s .co m PdfWriter.getInstance(document, new FileOutputStream("rapport_joueurs.pdf")); document.open(); com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png"); document.add(image); document.add(new Paragraph("Liste des joueurs", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD))); document.add(new Paragraph(" ")); for (int i = 0; i < joueurs.size(); i++) { document.add(new Paragraph(" ")); document.add(new Paragraph(joueurs.get(i).getNom_club())); document.add(new Paragraph(" ")); Integer val = joueurs.get(i).getId(); String val1 = joueurs.get(i).getNomJoueur(); String val2 = joueurs.get(i).getPrenomJoueur(); String val3 = joueurs.get(i).getDateNaissance(); String val4 = joueurs.get(i).getCarriere(); String val5 = joueurs.get(i).getSexe(); Integer val6 = joueurs.get(i).getPoints(); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("Joueur id: " + val)); cell.setColspan(4); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); table.addCell("Nom"); table.addCell(val1); table.addCell("Prenom"); table.addCell(val2); table.addCell("Date de naissance"); table.addCell(val3); table.addCell("Carriere"); table.addCell(val4); table.addCell("sexe"); table.addCell(val5); table.addCell("points"); table.addCell(val6.toString()); document.add(table); } document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Federation Tunisenne de Tennis")); document.close(); JOptionPane.showMessageDialog(null, "Rapport Enregistrer"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }