List of usage examples for com.lowagie.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(float widthPercentage)
From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) { try {//from w w w .j a v a2s . com String activity = ""; if (step.getResolvedState() != null) { State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState()); activity = resolvedState.getLabel(getRole(), getLanguage()); } String sAction = null; try { if ("#question#".equals(step.getAction())) { sAction = getString("processManager.question"); } else if ("#response#".equals(step.getAction())) { sAction = getString("processManager.response"); } else if ("#reAssign#".equals(step.getAction())) { sAction = getString("processManager.reAffectation"); } else { Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction()); sAction = action.getLabel(getRole(), getLanguage()); } } catch (WorkflowException we) { sAction = "##"; } String actor = getBestUserDetail().getDisplayedName(); String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage()); String header = ""; if (StringUtil.isDefined(activity)) { header += activity + " - "; } header += sAction + " (" + actor + " - " + date + ")"; Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL); PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader)); pCell.setFixedHeight(28); pCell.setBackgroundColor(new Color(239, 239, 239)); pCell.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPTable pTable = new PdfPTable(1); pTable.setWidthPercentage(100); pTable.addCell(pCell); document.add(pTable); } catch (Exception e) { SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e); } }
From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepContent(HistoryStep step, com.lowagie.text.Document document) { try {//from www . ja v a2s. c om Form form; if ("#question#".equals(step.getAction()) || "#response#".equals(step.getAction())) { // TODO form = null; } else { form = getProcessInstance().getProcessModel().getPresentationForm(step.getAction(), getRole(), getLanguage()); } XmlForm xmlForm = (XmlForm) form; if (xmlForm != null && step.getActionRecord() != null) { DataRecord data = step.getActionRecord(); VersioningUtil versioningUtil = new VersioningUtil(); // Force simpletext displayers because itext cannot display HTML Form fields (select, // radio...) float[] colsWidth = { 25, 75 }; PdfPTable tableContent = new PdfPTable(colsWidth); tableContent.setWidthPercentage(100); PdfPCell cell = null; Field field; String fieldLabel; String fieldValue = ""; Font fontLabel = new Font(Font.HELVETICA, 10, Font.BOLD); Font fontValue = new Font(Font.HELVETICA, 10, Font.NORMAL); List<FieldTemplate> fieldTemplates = xmlForm.getFieldTemplates(); for (FieldTemplate fieldTemplate1 : fieldTemplates) { GenericFieldTemplate fieldTemplate = (GenericFieldTemplate) fieldTemplate1; fieldLabel = fieldTemplate.getLabel("fr"); field = data.getField(fieldTemplate.getFieldName()); String componentId = step.getProcessInstance().getProcessModel().getModelId(); // fieldValue = data.getField(fieldTemplate.getFieldName()).getValue(); //wysiwyg field if ("wysiwyg".equals(fieldTemplate.getDisplayerName())) { String file = WysiwygFCKFieldDisplayer.getFile(componentId, getProcessInstance().getInstanceId(), fieldTemplate.getFieldName(), getLanguage()); //Extract the text content of the html code Source source = new Source(file); if (source != null) { fieldValue = source.getTextExtractor().toString(); } } //Field file type else if (FileField.TYPE.equals(fieldTemplate.getDisplayerName()) && StringUtil.isDefined(field.getValue())) { boolean fromCompoVersion = "yes".equals(getOrganizationController() .getComponentParameterValue(componentId, "versionControl")); //Versioning Used if (fromCompoVersion) { DocumentVersion documentVersion = versioningUtil .getDocumentVersion(new DocumentVersionPK(Integer.parseInt(field.getValue()))); if (documentVersion != null) { fieldValue = documentVersion.getLogicalName(); } } else { AttachmentDetail attDetail = AttachmentController .searchAttachmentByPK(new AttachmentPK(field.getValue(), componentId)); if (attDetail != null) { fieldValue = attDetail.getLogicalName(getLanguage()); } } } //Field date type else if (fieldTemplate.getTypeName().equals("date")) { fieldValue = DateUtil.getOutputDate(fieldValue, "fr"); } //Others fields type else { fieldTemplate.setDisplayerName("simpletext"); fieldValue = field.getValue(getLanguage()); } cell = new PdfPCell(new Phrase(fieldLabel, fontLabel)); cell.setBorderWidth(0); cell.setPaddingBottom(5); tableContent.addCell(cell); cell = new PdfPCell(new Phrase(fieldValue, fontValue)); cell.setBorderWidth(0); cell.setPaddingBottom(5); tableContent.addCell(cell); } document.add(tableContent); } } catch (Exception e) { SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e); } }
From source file:com.slamd.report.PDFReportGenerator.java
License:Open Source License
/** * Writes the table of contents to the document. * * @param document The document to which the contents are to be written. * * @return {@code true} if the contents information was written to the * PDF document, or {@code false} if not. * * @throws DocumentException If a problem occurs while writing the contents. *//*from w w w .j a v a 2 s.c o m*/ private boolean writeContents(Document document) throws DocumentException { // First, make sure that there is actually something to write. If we're // only going to write information for a single job or optimizing job, then // there is no reason to have a contents section. if (((reportJobs.length == 1) && (reportOptimizingJobs.length == 0)) || ((reportJobs.length == 0) && (reportOptimizingJobs.length == 1))) { return false; } if (reportJobs.length > 0) { // Write the job data header. Paragraph p = new Paragraph("Job Data", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK)); document.add(p); // Create a table with the list of jobs. PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); writeTableHeaderCell(table, "Job ID"); writeTableHeaderCell(table, "Description"); writeTableHeaderCell(table, "Job Type"); for (int i = 0; i < reportJobs.length; i++) { Job job = reportJobs[i]; Anchor anchor = new Anchor(job.getJobID(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE)); anchor.setReference('#' + job.getJobID()); table.addCell(new PdfPCell(anchor)); String descriptionStr = job.getJobDescription(); if ((descriptionStr == null) || (descriptionStr.length() == 0)) { descriptionStr = "(Not Specified)"; } writeTableCell(table, descriptionStr); writeTableCell(table, job.getJobClass().getJobName()); } document.add(table); // Write a blank line between the job data and optimizing job data. document.add(new Paragraph(" ")); } if (reportOptimizingJobs.length > 0) { // Write the optimizing job data header. Paragraph p = new Paragraph("Optimizing Job Data", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK)); document.add(p); // Create a table with the list of jobs. PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); writeTableHeaderCell(table, "Optimizing Job ID"); writeTableHeaderCell(table, "Description"); writeTableHeaderCell(table, "Job Type"); for (int i = 0; i < reportOptimizingJobs.length; i++) { OptimizingJob optimizingJob = reportOptimizingJobs[i]; Anchor anchor = new Anchor(optimizingJob.getOptimizingJobID(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE)); anchor.setReference('#' + optimizingJob.getOptimizingJobID()); table.addCell(new PdfPCell(anchor)); String descriptionStr = optimizingJob.getDescription(); if ((descriptionStr == null) || (descriptionStr.length() == 0)) { descriptionStr = "(Not Specified)"; } writeTableCell(table, descriptionStr); writeTableCell(table, optimizingJob.getJobClass().getJobName()); } document.add(table); } return true; }
From source file:com.slamd.report.PDFReportGenerator.java
License:Open Source License
/** * Writes information about the provided job to the document. * * @param document The document to which the job information should be * written./*from w w w. j a va 2 s . c om*/ * @param job The job to include in the document. * * @throws DocumentException If a problem occurs while writing the contents. */ private void writeJob(Document document, Job job) throws DocumentException { Anchor anchor = new Anchor("Job " + job.getJobID(), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK)); anchor.setName(job.getJobID()); Paragraph p = new Paragraph(anchor); document.add(p); // Write the general information to the document. p = new Paragraph("General Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); writeTableCell(table, "Job ID"); writeTableCell(table, job.getJobID()); String optimizingJobID = job.getOptimizingJobID(); if ((optimizingJobID != null) && (optimizingJobID.length() > 0)) { writeTableCell(table, "Optimizing Job ID"); writeTableCell(table, optimizingJobID); } String descriptionStr = job.getJobDescription(); if ((descriptionStr == null) || (descriptionStr.length() == 0)) { descriptionStr = "(Not Specified)"; } writeTableCell(table, "Job Description"); writeTableCell(table, descriptionStr); writeTableCell(table, "Job Type"); writeTableCell(table, job.getJobClassName()); writeTableCell(table, "Job Class"); writeTableCell(table, job.getJobClass().getClass().getName()); writeTableCell(table, "Job State"); writeTableCell(table, job.getJobStateString()); document.add(table); // Write the schedule config if appropriate. if (includeScheduleConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Schedule Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Date startTime = job.getStartTime(); String startStr; if (startTime == null) { startStr = "(Not Available)"; } else { startStr = dateFormat.format(startTime); } writeTableCell(table, "Scheduled Start Time"); writeTableCell(table, startStr); Date stopTime = job.getStopTime(); String stopStr; if (stopTime == null) { stopStr = "(Not Specified)"; } else { stopStr = dateFormat.format(stopTime); } writeTableCell(table, "Scheduled Stop Time"); writeTableCell(table, stopStr); int duration = job.getDuration(); String durationStr; if (duration > 0) { durationStr = duration + " seconds"; } else { durationStr = "(Not Specified)"; } writeTableCell(table, "Scheduled Duration"); writeTableCell(table, durationStr); writeTableCell(table, "Number of Clients"); writeTableCell(table, String.valueOf(job.getNumberOfClients())); String[] requestedClients = job.getRequestedClients(); if ((requestedClients != null) && (requestedClients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < requestedClients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Requested Clients"); table.addCell(clientTable); } String[] monitorClients = job.getResourceMonitorClients(); if ((monitorClients != null) && (monitorClients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < monitorClients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Resource Monitor Clients"); table.addCell(clientTable); } writeTableCell(table, "Threads per Client"); writeTableCell(table, String.valueOf(job.getThreadsPerClient())); writeTableCell(table, "Thread Startup Delay"); writeTableCell(table, job.getThreadStartupDelay() + " milliseconds"); writeTableCell(table, "Statistics Collection Interval"); writeTableCell(table, job.getCollectionInterval() + " seconds"); document.add(table); } // Write the job-specific parameter information if appropriate. if (includeJobConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Parameter Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Parameter[] params = job.getParameterList().getParameters(); for (int i = 0; i < params.length; i++) { writeTableCell(table, params[i].getDisplayName()); writeTableCell(table, params[i].getDisplayValue()); } document.add(table); } // Write the statistical data if appropriate. if (includeStats && job.hasStats()) { document.add(new Paragraph(" ")); p = new Paragraph("General Execution Data", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Date actualStartTime = job.getActualStartTime(); String startStr; if (actualStartTime == null) { startStr = "(Not Available)"; } else { startStr = dateFormat.format(actualStartTime); } writeTableCell(table, "Actual Start Time"); writeTableCell(table, startStr); Date actualStopTime = job.getActualStopTime(); String stopStr; if (actualStopTime == null) { stopStr = "(Not Available)"; } else { stopStr = dateFormat.format(actualStopTime); } writeTableCell(table, "Actual Stop Time"); writeTableCell(table, stopStr); int actualDuration = job.getActualDuration(); String durationStr; if (actualDuration > 0) { durationStr = actualDuration + " seconds"; } else { durationStr = "(Not Available)"; } writeTableCell(table, "Actual Duration"); writeTableCell(table, durationStr); String[] clients = job.getStatTrackerClientIDs(); if ((clients != null) && (clients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < clients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(clients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Clients Used"); table.addCell(clientTable); } document.add(table); String[] trackerNames = job.getStatTrackerNames(); for (int i = 0; i < trackerNames.length; i++) { StatTracker[] trackers = job.getStatTrackers(trackerNames[i]); if ((trackers != null) && (trackers.length > 0)) { document.newPage(); StatTracker tracker = trackers[0].newInstance(); tracker.aggregate(trackers); document.add(new Paragraph(" ")); document.add(new Paragraph(trackerNames[i], FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK))); String[] summaryNames = tracker.getSummaryLabels(); String[] summaryValues = tracker.getSummaryData(); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 50 }); for (int j = 0; j < summaryNames.length; j++) { writeTableCell(table, summaryNames[j]); writeTableCell(table, summaryValues[j]); } document.add(table); if (includeGraphs) { try { ParameterList params = tracker.getGraphParameterStubs(job); BufferedImage graphImage = tracker.createGraph(job, Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_GRAPH_HEIGHT, params); Image image = Image.getInstance(imageToByteArray(graphImage)); image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5)); document.add(image); } catch (Exception e) { } } } } } // Write the resource monitor data if appropriate. if (includeMonitorStats && job.hasResourceStats()) { String[] trackerNames = job.getResourceStatTrackerNames(); for (int i = 0; i < trackerNames.length; i++) { StatTracker[] trackers = job.getResourceStatTrackers(trackerNames[i]); if ((trackers != null) && (trackers.length > 0)) { document.newPage(); StatTracker tracker = trackers[0].newInstance(); tracker.aggregate(trackers); document.add(new Paragraph(" ")); document.add(new Paragraph(trackerNames[i], FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK))); String[] summaryNames = tracker.getSummaryLabels(); String[] summaryValues = tracker.getSummaryData(); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 50 }); for (int j = 0; j < summaryNames.length; j++) { writeTableCell(table, summaryNames[j]); writeTableCell(table, summaryValues[j]); } document.add(table); if (includeGraphs) { try { ParameterList params = tracker.getGraphParameterStubs(job); BufferedImage graphImage = tracker.createMonitorGraph(job, Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_MONITOR_GRAPH_HEIGHT, params); Image image = Image.getInstance(imageToByteArray(graphImage)); image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5)); document.add(image); } catch (Exception e) { } } } } } }
From source file:com.slamd.report.PDFReportGenerator.java
License:Open Source License
/** * Writes information about the provided optimizing job to the document. * * @param document The document to which the job information should be * written.//www . j av a 2 s. co m * @param optimizingJob The optimizing job to include in the document. * * @throws DocumentException If a problem occurs while writing the contents. */ private void writeOptimizingJob(Document document, OptimizingJob optimizingJob) throws DocumentException { Anchor anchor = new Anchor("Optimizing Job " + optimizingJob.getOptimizingJobID(), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK)); anchor.setName(optimizingJob.getOptimizingJobID()); Paragraph p = new Paragraph(anchor); document.add(p); // Write the general information to the document. p = new Paragraph("General Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); writeTableCell(table, "Optimizing Job ID"); writeTableCell(table, optimizingJob.getOptimizingJobID()); writeTableCell(table, "Job Type"); writeTableCell(table, optimizingJob.getJobClassName()); String descriptionStr = optimizingJob.getDescription(); if ((descriptionStr == null) || (descriptionStr.length() == 0)) { descriptionStr = "(Not Specified)"; } writeTableCell(table, "Base Description"); writeTableCell(table, descriptionStr); writeTableCell(table, "Include Thread Count in Description"); writeTableCell(table, String.valueOf(optimizingJob.includeThreadsInDescription())); writeTableCell(table, "Job State"); writeTableCell(table, Constants.jobStateToString(optimizingJob.getJobState())); document.add(table); // Write the schedule config to the document if appropriate. if (includeScheduleConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Schedule Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Date startTime = optimizingJob.getStartTime(); String startStr; if (startTime == null) { startStr = "(Not Available)"; } else { startStr = dateFormat.format(startTime); } writeTableCell(table, "Scheduled Start Time"); writeTableCell(table, startStr); int duration = optimizingJob.getDuration(); String durationStr; if (duration > 0) { durationStr = duration + " seconds"; } else { durationStr = "(Not Specified)"; } writeTableCell(table, "Job Duration"); writeTableCell(table, durationStr); writeTableCell(table, "Delay Between Iterations"); writeTableCell(table, optimizingJob.getDelayBetweenIterations() + " seconds"); writeTableCell(table, "Number of Clients"); writeTableCell(table, String.valueOf(optimizingJob.getNumClients())); String[] requestedClients = optimizingJob.getRequestedClients(); if ((requestedClients != null) && (requestedClients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < requestedClients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Requested Clients"); table.addCell(clientTable); } String[] monitorClients = optimizingJob.getResourceMonitorClients(); if ((monitorClients != null) && (monitorClients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < monitorClients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Resource Monitor Clients"); table.addCell(clientTable); } writeTableCell(table, "Minimum Number of Threads"); writeTableCell(table, String.valueOf(optimizingJob.getMinThreads())); int maxThreads = optimizingJob.getMaxThreads(); String maxThreadsStr; if (maxThreads > 0) { maxThreadsStr = String.valueOf(maxThreads); } else { maxThreadsStr = "(Not Specified)"; } writeTableCell(table, "Maximum Number of Threads"); writeTableCell(table, maxThreadsStr); writeTableCell(table, "Thread Increment Between Iterations"); writeTableCell(table, String.valueOf(optimizingJob.getThreadIncrement())); writeTableCell(table, "Statistics Collection Interval"); writeTableCell(table, optimizingJob.getCollectionInterval() + " seconds"); document.add(table); } // Get the optimization algorithm used. OptimizationAlgorithm optimizationAlgorithm = optimizingJob.getOptimizationAlgorithm(); ParameterList paramList = optimizationAlgorithm.getOptimizationAlgorithmParameters(); Parameter[] optimizationParams = paramList.getParameters(); // Write the optimizing config to the document if appropriate. if (includeScheduleConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Optimization Settings", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); for (int i = 0; i < optimizationParams.length; i++) { writeTableCell(table, optimizationParams[i].getDisplayName()); writeTableCell(table, optimizationParams[i].getDisplayValue()); } writeTableCell(table, "Maximum Consecutive Non-Improving Iterations"); writeTableCell(table, String.valueOf(optimizingJob.getMaxNonImproving())); writeTableCell(table, "Re-Run Best Iteration"); writeTableCell(table, String.valueOf(optimizingJob.reRunBestIteration())); int reRunDuration = optimizingJob.getReRunDuration(); String durationStr; if (reRunDuration > 0) { durationStr = reRunDuration + " seconds"; } else { durationStr = "(Not Specified)"; } writeTableCell(table, "Re-Run Duration"); writeTableCell(table, durationStr); document.add(table); } // Write the job-specific config to the document if appropriate. if (includeJobConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Parameter Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Parameter[] params = optimizingJob.getParameters().getParameters(); for (int i = 0; i < params.length; i++) { writeTableCell(table, params[i].getDisplayName()); writeTableCell(table, params[i].getDisplayValue()); } document.add(table); } // Write the statistical data to the document if appropriate. if (includeStats && optimizingJob.hasStats()) { document.add(new Paragraph(" ")); p = new Paragraph("Execution Data", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Date actualStartTime = optimizingJob.getActualStartTime(); String startTimeStr; if (actualStartTime == null) { startTimeStr = "(Not Available)"; } else { startTimeStr = dateFormat.format(actualStartTime); } writeTableCell(table, "Actual Start Time"); writeTableCell(table, startTimeStr); Date actualStopTime = optimizingJob.getActualStopTime(); String stopTimeStr; if (actualStopTime == null) { stopTimeStr = "(Not Available)"; } else { stopTimeStr = dateFormat.format(actualStopTime); } writeTableCell(table, "Actual Stop Time"); writeTableCell(table, stopTimeStr); Job[] iterations = optimizingJob.getAssociatedJobs(); if ((iterations != null) && (iterations.length > 0)) { writeTableCell(table, "Job Iterations Completed"); writeTableCell(table, String.valueOf(iterations.length)); int optimalThreadCount = optimizingJob.getOptimalThreadCount(); String threadStr; if (optimalThreadCount > 0) { threadStr = String.valueOf(optimalThreadCount); } else { threadStr = "(Not Available)"; } writeTableCell(table, "Optimal Thread Count"); writeTableCell(table, threadStr); double optimalValue = optimizingJob.getOptimalValue(); String valueStr; if (optimalThreadCount > 0) { valueStr = decimalFormat.format(optimalValue); } else { valueStr = "(Not Available)"; } writeTableCell(table, "Optimal Value"); writeTableCell(table, valueStr); String optimalID = optimizingJob.getOptimalJobID(); writeTableCell(table, "Optimal Job Iteration"); if ((optimalID == null) || (optimalID.length() == 0)) { writeTableCell(table, "(Not Available)"); } else if (includeOptimizingIterations) { anchor = new Anchor(optimalID, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE)); anchor.setReference('#' + optimalID); table.addCell(new PdfPCell(anchor)); } else { writeTableCell(table, optimalID); } } Job reRunIteration = optimizingJob.getReRunIteration(); if (reRunIteration != null) { writeTableCell(table, "Re-Run Iteration"); if (includeOptimizingIterations) { anchor = new Anchor(reRunIteration.getJobID(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE)); anchor.setReference('#' + reRunIteration.getJobID()); table.addCell(new PdfPCell(anchor)); } else { writeTableCell(table, reRunIteration.getJobID()); } String valueStr; try { double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(reRunIteration); valueStr = decimalFormat.format(iterationValue); } catch (Exception e) { valueStr = "N/A"; } writeTableCell(table, "Re-Run Iteration Value"); writeTableCell(table, valueStr); } document.add(table); if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) { document.add(new Paragraph(" ")); p = new Paragraph("Job Iterations", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 50 }); for (int i = 0; i < iterations.length; i++) { String valueStr; try { double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(iterations[i]); valueStr = decimalFormat.format(iterationValue); } catch (Exception e) { valueStr = "N/A"; } anchor = new Anchor(iterations[i].getJobID(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE)); anchor.setReference('#' + iterations[i].getJobID()); table.addCell(new PdfPCell(anchor)); writeTableCell(table, valueStr); } document.add(table); } if (includeGraphs && (iterations != null) && (iterations.length > 0)) { String[] statNames = iterations[0].getStatTrackerNames(); for (int j = 0; j < statNames.length; j++) { StatTracker[] trackers = iterations[0].getStatTrackers(statNames[j]); if ((trackers != null) && (trackers.length > 0)) { StatTracker tracker = trackers[0].newInstance(); tracker.aggregate(trackers); try { document.newPage(); ParameterList params = tracker.getGraphParameterStubs(iterations); BufferedImage graphImage = tracker.createGraph(iterations, Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_GRAPH_HEIGHT, params); Image image = Image.getInstance(imageToByteArray(graphImage)); image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5)); document.add(image); } catch (Exception e) { } } } } if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) { for (int i = 0; i < iterations.length; i++) { document.newPage(); writeJob(document, iterations[i]); } } if (includeOptimizingIterations && (reRunIteration != null)) { document.newPage(); writeJob(document, reRunIteration); } } }
From source file:com.slamd.report.PDFReportGenerator.java
License:Open Source License
/** * Performs the appropriate action necessary when starting a new page. In * this case, we will write the SLAMD header to the top of the page. * * @param writer The writer used to write the PDF document. * @param document The PDF document being written. *///from w w w . java2 s .com public void onStartPage(PdfWriter writer, Document document) { try { PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); PdfPCell blueCell = new PdfPCell(new Phrase(" \n ")); blueCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); blueCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); blueCell.setBackgroundColor(new Color(0x59, 0x4F, 0xBF)); blueCell.setBorderWidth(inchesToPoints(1.0 / 16)); blueCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); blueCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(blueCell); Phrase titlePhrase = new Phrase("SLAMD Generated Report", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0x59, 0x4F, 0xBF))); PdfPCell yellowCell = new PdfPCell(titlePhrase); yellowCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); yellowCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); yellowCell.setBackgroundColor(new Color(0xFB, 0xE2, 0x49)); yellowCell.setBorderWidth(inchesToPoints(1.0 / 16)); yellowCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); yellowCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(yellowCell); Phrase versionPhrase = new Phrase("Version " + DynamicConstants.SLAMD_VERSION, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0xFF, 0xFF, 0xFF))); PdfPCell redCell = new PdfPCell(versionPhrase); redCell.setHorizontalAlignment(Cell.ALIGN_RIGHT); redCell.setVerticalAlignment(Cell.ALIGN_MIDDLE); redCell.setBackgroundColor(new Color(0xD1, 0x21, 0x24)); redCell.setBorderWidth(inchesToPoints(1.0 / 16)); redCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); redCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(redCell); document.add(table); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.songbook.pc.exporter.PdfExporter.java
License:Open Source License
private Element buildQrCodeSection() throws IOException, DocumentException { // Load images Image qrApkImage = PngImage/*from w w w . java2s . c o m*/ .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_apk_qr.png")); Image qrPdfImage = PngImage .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_pdf_qr.png")); PdfPCell cell = new PdfPCell((Phrase) null); cell.setBorder(PdfPCell.NO_BORDER); cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.setWidths(new float[] { 1, 2, 1 }); cell.setImage(qrApkImage); table.addCell(cell); cell.setImage(null); table.addCell(cell); cell.setImage(qrPdfImage); table.addCell(cell); cell.setImage(null); cell.setPhrase(new Phrase("APP")); table.addCell(cell); cell.setPhrase(null); table.addCell(cell); cell.setPhrase(new Phrase("PDF")); table.addCell(cell); cell.setPhrase(null); return table; }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosDerecha(Paragraph datosDerecha) throws Exception { ciudad = Cotizacion.PanelCotizacion.labelCiudad.getText(); Connection conexion = null;//from w w w . j av a 2 s . co m try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); // System.out.println("nombre++++----> "+nombreCliente); ResultSet rs = stm.executeQuery("SELECT * FROM todolonas.ajustes;"); while (rs.next()) { telefonoNegocio = rs.getString("telefonoNegocio"); numeroCelular = rs.getString("numeroCelular"); correoNegocio = rs.getString("correoNegocio"); domicilioNegocio = rs.getString("domicilioNegocio"); RFC = rs.getString("RFC"); leyendaCotizacion = rs.getString("leyendaCotizacion"); colonia = rs.getString("colonia"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.addCell(""); table.addCell(telefonoNegocio); table.addCell(""); table.addCell(numeroCelular); table.addCell(""); table.addCell(correoNegocio); table.addCell(""); table.addCell(domicilioNegocio); table.addCell(""); table.addCell(colonia); table.addCell(""); table.addCell(RFC); table.addCell(""); table.addCell(ciudad); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_RIGHT); datosDerecha.add(table); }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosDerecha2(Paragraph datosDerecha2) { fecha = PanelCotizacion.labelObtenerFecha.getText(); ubicacion = PanelCotizacion.cajaAsunto.getText(); asunto = PanelCotizacion.cajaUbicacion.getText(); PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Fecha"); table2.addCell(fecha);/*from w w w . ja v a 2 s . c o m*/ table2.addCell("Ubicacin"); table2.addCell(ubicacion); table2.addCell("Asunto"); table2.addCell(asunto); table2.setWidthPercentage(50); table2.setHorizontalAlignment(350); table2.setHorizontalAlignment(Element.ALIGN_RIGHT); datosDerecha2.add(table2); }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosEspecificaciones(Paragraph datosNormal) throws BadElementException { Connection conexion = null;/*from ww w. j a v a 2s . c o m*/ try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); ResultSet rs = stm.executeQuery("select max(numero) as numero from todolonas.cotizacion;"); while (rs.next()) { idCotiza = rs.getInt("numero"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); ResultSet rs = stm.executeQuery( "SELECT especificacionTrabajo FROM todolonas.cotizacion where numero = '" + idCotiza + "';"); while (rs.next()) { especificacionTrabajo = rs.getString("especificacionTrabajo"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } if (especificacionTrabajo.equals("NA")) { System.out.println("no hay especificacion trabajo"); } else { PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Especificacin Trabajo"); table2.addCell(especificacionTrabajo); table2.setWidthPercentage(70); table2.setHorizontalAlignment(Element.ALIGN_LEFT); agregarLineasEnBlanco(datosNormal, 1); datosNormal.add(table2); } try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); // System.out.println("nombre++++----> "+nombreCliente); ResultSet rs = stm.executeQuery( "SELECT especificacionDiseno FROM todolonas.cotizacion where numero = '" + idCotiza + "';"); while (rs.next()) { especificacionDiseno = rs.getString("especificacionDiseno"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } if (especificacionDiseno.equals("NA")) { System.out.println("no hay especificacion trabajo"); } else { PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Especificacin Diseo"); table2.addCell(especificacionDiseno); table2.setWidthPercentage(70); table2.setHorizontalAlignment(Element.ALIGN_LEFT); agregarLineasEnBlanco(datosNormal, 1); datosNormal.add(table2); } }