List of usage examples for com.lowagie.text Document add
public boolean add(Element element) throws DocumentException
Element
to the Document
. From source file:com.safetys.framework.jmesa.view.pdfp.PdfPViewExporter.java
License:Apache License
public void export() throws Exception { com.lowagie.text.Document document = new com.lowagie.text.Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();/*from w ww . j a v a2s.co m*/ PdfPView pdfView = (PdfPView) getView(); document.add(pdfView.getTableCaption()); document.add(pdfView.render()); document.close(); HttpServletResponse response = getResponse(); responseHeaders(response); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); }
From source file:com.senacor.wbs.web.project.ProjectListPanel.java
License:Apache License
public ProjectListPanel(final String id, final List<Project> projects) { super(id);//from ww w. ja v a 2 s . c o m this.locale = getLocale(); SortableListDataProvider<Project> projectProvider = new SortableListDataProvider<Project>(projects) { @Override protected Locale getLocale() { return ProjectListPanel.this.getLocale(); } public IModel model(final Object object) { return new CompoundPropertyModel(object); } }; projectProvider.setSort("name", true); dataView = new DataView("projects", projectProvider, 4) { @Override protected void populateItem(final Item item) { Project project = (Project) item.getModelObject(); PageParameters pageParameters = new PageParameters(); pageParameters.put("projectId", project.getId()); item.add(new BookmarkablePageLink("tasks", ProjectDetailsPage.class, pageParameters) .add(new Label("id"))); item.add(new Label("kuerzel")); item.add(new Label("titel", project.getName())); item.add(new Label("budget")); item.add(new Label("costPerHour")); item.add(new Label("start")); item.add(new Label("ende")); item.add(new Label("state")); // Alternieren der Farbe zwischen geraden und // ungeraden Zeilen item.add(new AttributeModifier("class", true, new AbstractReadOnlyModel() { @Override public Object getObject() { return (item.getIndex() % 2 == 1) ? "even" : "odd"; } })); } }; add(dataView); Form localeForm = new Form("localeForm"); ImageButton deButton = new ImageButton("langde", new ResourceReference(BaseWBSPage.class, "de.png")) { @Override public void onSubmit() { ProjectListPanel.this.locale = Locale.GERMANY; } }; localeForm.add(deButton); ImageButton usButton = new ImageButton("langus", new ResourceReference(BaseWBSPage.class, "us.png")) { @Override public void onSubmit() { ProjectListPanel.this.locale = Locale.US; } }; localeForm.add(usButton); add(localeForm); final IResourceStream pdfResourceStream = new AbstractResourceStreamWriter() { public void write(final OutputStream output) { Document document = new Document(); try { PdfWriter.getInstance(document, output); document.open(); // document.add(new // Paragraph("WBS-Projektliste")); // document.add(new Paragraph("")); PdfPTable table = new PdfPTable(new float[] { 1f, 1f, 2f, 1f }); PdfPCell cell = new PdfPCell(new Paragraph("WBS-Projektliste")); cell.setColspan(4); cell.setGrayFill(0.8f); table.addCell(cell); table.addCell("ID"); table.addCell("Krzel"); table.addCell("Titel"); table.addCell("Budget in PT"); for (Project project : projects) { table.addCell("" + project.getId()); table.addCell(project.getKuerzel()); table.addCell(project.getName()); table.addCell("" + project.getBudget()); } document.add(table); document.close(); } catch (DocumentException e) { throw new RuntimeException(e); } } public String getContentType() { return "application/pdf"; } }; WebResource projectsResource = new WebResource() { { setCacheable(false); } @Override public IResourceStream getResourceStream() { return pdfResourceStream; } @Override protected void setHeaders(final WebResponse response) { super.setHeaders(response); // response.setAttachmentHeader("projekte.pdf"); } }; WebResource projectsResourceDL = new WebResource() { { setCacheable(false); } @Override public IResourceStream getResourceStream() { return pdfResourceStream; } @Override protected void setHeaders(final WebResponse response) { super.setHeaders(response); response.setAttachmentHeader("projekte.pdf"); } }; ResourceLink pdfDownload = new ResourceLink("pdfDownload", projectsResourceDL); ResourceLink pdfPopup = new ResourceLink("pdfPopup", projectsResource); PopupSettings popupSettings = new PopupSettings(PopupSettings.STATUS_BAR); popupSettings.setWidth(500); popupSettings.setHeight(700); pdfPopup.setPopupSettings(popupSettings); Link pdfReqTarget = new Link("pdfReqTarget") { @Override public void onClick() { RequestCycle.get() .setRequestTarget(new ResourceStreamRequestTarget(pdfResourceStream, "projekte.pdf")); } }; add(pdfReqTarget); add(pdfDownload); add(pdfPopup); add(new OrderByBorder("orderByKuerzel", "kuerzel", projectProvider)); add(new OrderByBorder("orderByName", "name", projectProvider)); add(new OrderByBorder("orderByBudget", "budget", projectProvider)); add(new OrderByBorder("orderByCostPerHour", "costPerHour", projectProvider)); add(new OrderByBorder("orderByStart", "start", projectProvider)); add(new OrderByBorder("orderByEnde", "ende", projectProvider)); add(new OrderByBorder("orderByState", "state", projectProvider)); add(new PagingNavigator("projectsNavigator", dataView)); }
From source file:com.shmsoft.dmass.print.Html2Pdf.java
License:Apache License
/** * Bad rendering, perhaps used only for Windows *///from ww w.j a va 2 s. c o m @SuppressWarnings({ "rawtypes", "unchecked" }) private static void convertHtml2Pdf(Reader htmlReader, String outputFile) throws Exception { Document pdfDocument = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(pdfDocument, baos); pdfDocument.open(); StyleSheet styles = new StyleSheet(); styles.loadTagStyle("body", "font", "Times New Roman"); ImageProvider imageProvider = new ImageProvider() { @Override public Image getImage(String src, HashMap arg1, ChainedProperties arg2, DocListener arg3) { try { Image image = Image.getInstance(IOUtils.toByteArray( getClass().getClassLoader().getResourceAsStream(ParameterProcessing.NO_IMAGE_FILE))); return image; } catch (Exception e) { System.out.println("Problem with html->pdf imaging, image provider fault"); } return null; } }; HashMap interfaceProps = new HashMap(); interfaceProps.put("img_provider", imageProvider); ArrayList arrayElementList = HTMLWorker.parseToList(htmlReader, styles, interfaceProps); for (int i = 0; i < arrayElementList.size(); ++i) { Element e = (Element) arrayElementList.get(i); pdfDocument.add(e); } pdfDocument.close(); byte[] bs = baos.toByteArray(); File pdfFile = new File(outputFile); FileOutputStream out = new FileOutputStream(pdfFile); out.write(bs); out.close(); }
From source file:com.siacra.beans.ExporterBean.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; HeaderFooter header = new HeaderFooter(new Phrase(this.getTitle()), false); pdf.setHeader(header);/*from w w w . ja v a 2s . c om*/ HeaderFooter footer = new HeaderFooter(new Phrase("Pagina"), new Phrase("")); pdf.setFooter(footer); pdf.open(); pdf.setPageSize(PageSize.LETTER); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "img" + File.separator + "minerva.png"; pdf.add(Image.getInstance(logo)); }
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 ww . ja 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 ww . j av a 2s .c o m * @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./*w w w .j a v a 2 s.c om*/ * @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. *//*w w w. j a v a 2s.c o m*/ 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 PageStats generatePDF(List<SongNode> songList, File outputFile) throws IOException, DocumentException { logger.info("Starting export to PDF file {}.", outputFile.getAbsolutePath()); // Initialize Writer Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); PageStats pageStats = new PageStats(); writer.setPageEvent(pageStats);/*from w ww .j a va2 s . c o m*/ // Initialize document document.setPageSize(PageSize.A4); document.setMargins(35 * POINTS_PER_MM, 10 * POINTS_PER_MM, 7 * POINTS_PER_MM, 7 * POINTS_PER_MM); document.setMarginMirroring(true); document.open(); // Add QR codes Element qrCodeSection = buildQrCodeSection(); document.add(qrCodeSection); // Line separator document.add(verseSpacing); document.add(new LineSeparator()); document.add(verseSpacing); // Build TOC Chunk tocTitle = new Chunk("SONG BOOK - TABLE OF CONTENTS", songTitleFont); tocTitle.setLocalDestination("TOC"); document.add(new Paragraph(tocTitle)); for (int i = 0; i < songList.size(); i++) { SongNode songNode = songList.get(i); int chapterNumber = i + 1; Chunk tocEntry = new Chunk(chapterNumber + ". " + songNode.getTitle(), textFont); tocEntry.setLocalGoto("SONG::" + chapterNumber); document.add(new Paragraph(tocEntry)); } document.newPage(); pageStats.setSectionLength("TOC", pageStats.getCurrentPage() - 1); // Build document for (int i = 0; i < songList.size(); i++) { // Get song node SongNode songNode = songList.get(i); // Mark song start int songStartPage = pageStats.getCurrentPage(); // Write song document.add(buildChapter(songNode, i + 1)); document.newPage(); // Record song length pageStats.setSectionLength(songNode.getTitle(), pageStats.getCurrentPage() - songStartPage); } // Close document document.close(); logger.info("COMPLETED export to PDF file {}.", outputFile.getAbsolutePath()); return pageStats; }
From source file:com.stratelia.webactiv.almanach.control.AlmanachPdfGenerator.java
License:Open Source License
static public void buildPdf(String name, AlmanachSessionController almanach, String mode) throws AlmanachRuntimeException { try {/* w ww . j a v a 2s. c o m*/ SilverTrace.info("almanach", "AlmanachPdfGenerator.buildPdf()", "root.MSG_GEN_ENTER_METHOD"); String fileName = FileRepositoryManager.getTemporaryPath(almanach.getSpaceId(), almanach.getComponentId()) + name; Document document = new Document(PageSize.A4, 50, 50, 50, 50); // we add some meta information to the document document.addAuthor(almanach.getSettings().getString("author", "")); document.addSubject(almanach.getSettings().getString("subject", "")); document.addCreationDate(); PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); try { Calendar currentDay = Calendar.getInstance(); currentDay.setTime(almanach.getCurrentDay()); String sHeader = almanach.getString("events"); if (mode.equals(PDF_MONTH_ALLDAYS) || mode.equals(PDF_MONTH_EVENTSONLY)) { sHeader += " " + almanach.getString("GML.mois" + currentDay.get(Calendar.MONTH)); } sHeader += " " + currentDay.get(Calendar.YEAR); HeaderFooter header = new HeaderFooter(new Phrase(sHeader), false); HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true); footer.setAlignment(Element.ALIGN_CENTER); document.setHeader(header); document.setFooter(footer); createFirstPage(almanach, document); document.newPage(); Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255)); Paragraph cTitle = new Paragraph(almanach.getString("Almanach") + " " + almanach.getString("GML.mois" + currentDay.get(Calendar.MONTH)) + " " + currentDay.get(Calendar.YEAR), titleFont); Chapter chapter = new Chapter(cTitle, 1); // Collection<EventDetail> events = // almanach.getListRecurrentEvent(mode.equals(PDF_YEAR_EVENTSONLY)); AlmanachCalendarView almanachView; if (PDF_YEAR_EVENTSONLY.equals(mode)) { almanachView = almanach.getYearlyAlmanachCalendarView(); } else { almanachView = almanach.getMonthlyAlmanachCalendarView(); } List<DisplayableEventOccurrence> occurrences = almanachView.getEvents(); generateAlmanach(chapter, almanach, occurrences, mode); document.add(chapter); } catch (Exception ex) { throw new AlmanachRuntimeException("PdfGenerator.generate", AlmanachRuntimeException.WARNING, "AlmanachRuntimeException.EX_PROBLEM_TO_GENERATE_PDF", ex); } document.close(); SilverTrace.info("almanach", "AlmanachPdfGenerator.buildPdf()", "root.MSG_GEN_EXIT_METHOD"); } catch (Exception e) { throw new AlmanachRuntimeException("PdfGenerator.generate", AlmanachRuntimeException.WARNING, "AlmanachRuntimeException.EX_PROBLEM_TO_GENERATE_PDF", e); } }