List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:com.servoy.extensions.plugins.pdf_output.PDFPrinterJob.java
License:Open Source License
@Override public synchronized void print() throws PrinterException { //do work/*from w w w . j a v a 2 s.c o m*/ if (printableDocument != null) { try { if (document == null) { Printable printable = printableDocument.getPrintable(0); PageFormat pf = printableDocument.getPageFormat(0); document = new Document(pageSize(pf), pageMargin("L", pf), //$NON-NLS-1$ pageMargin("R", pf), pageMargin("T", pf), //$NON-NLS-1$//$NON-NLS-2$ pageMargin("B", pf)); //$NON-NLS-1$ // we create a writer that listens to the document and // directs a PDF-stream to a file writer = PdfWriter.getInstance(document, os); document.open(); // we create a template and a Graphics2D object that // corresponds with it cb = writer.getDirectContent(); } int numPages = printableDocument.getNumberOfPages(); if (numPages == 0) document.add(new Paragraph(" ")); pagesPrinted = 0; for (int i = 0; i < numPages; i++) { pagesPrinted++; Printable printable = printableDocument.getPrintable(i); PageFormat pf = printableDocument.getPageFormat(i); document.setPageSize(pageSize(pf)); document.setMargins(pageMargin("L", pf), //$NON-NLS-1$ pageMargin("R", pf), pageMargin("T", pf), //$NON-NLS-1$//$NON-NLS-2$ pageMargin("B", pf)); //$NON-NLS-1$ cb.saveState(); Graphics2D g2d = cb.createGraphics((int) pf.getWidth(), (int) pf.getHeight(), mapper); printable.print(g2d, pf, i); g2d.dispose(); cb.restoreState(); document.newPage(); } totalPagesPrinted += pagesPrinted; if (!isMetaPrintJob) { close(); } } catch (Exception e) { Debug.error(e); } } }
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.// w w w. j a va 2 s. co 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.//from w w w . j av a 2s . c o 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.songbook.pc.exporter.PdfExporter.java
License:Open Source License
public PdfExporter(SongNodeLoader loader) { this.loader = loader; // Load fonts FontFactory.registerDirectories();//from ww w . ja va 2 s . c o m BaseFont timesFont = null; try { timesFont = BaseFont.createFont("C:/Windows/Fonts/times.ttf", BaseFont.CP1250, true); logger.info("Embedded TTF fonts from C:/Windows/Fonts"); } catch (Exception ex) { try { timesFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, true); logger.info("Embedded default fonts"); } catch (Exception ex1) { logger.error("Failed to load fonts ..."); } } // Initialize fonts if (timesFont != null) { songTitleFont = new Font(timesFont, 14f, Font.BOLD); textFont = new Font(timesFont, 11f, Font.NORMAL); chordFont = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, 11f, Font.BOLD); } else { songTitleFont = null; textFont = null; chordFont = null; } verseSpacing = new Paragraph(" "); verseSpacing.setLeading(5f, 0.5f); }
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 w w. j a v a2 s .co 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.songbook.pc.exporter.PdfExporter.java
License:Open Source License
private Chapter buildChapter(SongNode songNode, int chapterNumber) { // Title/*from w w w . j av a 2s . c o m*/ Chunk chapterTitle = new Chunk(songNode.getTitle(), songTitleFont); chapterTitle.setLocalDestination("SONG::" + chapterNumber); chapterTitle.setLocalGoto("TOC"); Chapter chapter = new Chapter(new Paragraph(chapterTitle), chapterNumber); for (VerseNode verseNode : songNode.getVerseList()) { processVerse(verseNode, chapter); } return chapter; }
From source file:com.stratelia.webactiv.kmelia.control.Callback.java
License:Open Source License
@Override public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) throws KmeliaRuntimeException { SilverTrace.info("kmelia", "Callback.handleSimpleTag", "root.MSG_ENTRY_METHOD", "t = " + t.toString()); try {// w w w. j a va 2s . c om if (BR.equals(t) || P.equals(t)) { if (paragraph != null) { paragraph.add(new Paragraph("\n")); } else { document.add(new Paragraph("\n")); } } } catch (Exception ex) { throw new KmeliaRuntimeException("Callback.handleSimpleTag", SilverpeasRuntimeException.WARNING, "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex); } }
From source file:com.stratelia.webactiv.kmelia.control.Callback.java
License:Open Source License
private void addText(final String text, final Font fnt) throws KmeliaRuntimeException { SilverTrace.info("kmelia", "Callback.addText", "root.MSG_ENTRY_METHOD", "text = " + text); String content = text;/* w w w . j ava 2s . c o m*/ try { content = escapeChars(content); if (cl != null) { cl = new Cell(new Chunk(content, fnt)); cl.setBorderWidth(0); is_was_text = true; } else if (paragraph != null) { paragraph.add(content); // paragraph.add( new Chunk( text, fnt ) ); } else { document.add(new Paragraph(content)); paragraph = null; } } catch (Exception ex) { throw new KmeliaRuntimeException("Callback.addText", SilverpeasRuntimeException.WARNING, "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex); } }
From source file:com.unicornlabs.kabouter.reporting.PowerReport.java
License:Apache License
public static void GeneratePowerReport(Date startDate, Date endDate) { try {/*from ww w . ja v a2 s. c om*/ Historian theHistorian = (Historian) BusinessObjectManager.getBusinessObject(Historian.class.getName()); ArrayList<String> powerLogDeviceIds = theHistorian.getPowerLogDeviceIds(); Document document = new Document(PageSize.A4, 50, 50, 50, 50); File outputFile = new File("PowerReport.pdf"); outputFile.createNewFile(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open(); document.add(new Paragraph("Power Report for " + startDate.toString() + " to " + endDate.toString())); document.newPage(); DecimalFormat df = new DecimalFormat("#.###"); for (String deviceId : powerLogDeviceIds) { ArrayList<Powerlog> powerlogs = theHistorian.getPowerlogs(deviceId, startDate, endDate); double total = 0; double max = 0; Date maxTime = startDate; double average = 0; XYSeries series = new XYSeries(deviceId); XYDataset dataset = new XYSeriesCollection(series); for (Powerlog log : powerlogs) { total += log.getPower(); if (log.getPower() > max) { max = log.getPower(); maxTime = log.getId().getLogtime(); } series.add(log.getId().getLogtime().getTime(), log.getPower()); } average = total / powerlogs.size(); document.add(new Paragraph("\nDevice: " + deviceId)); document.add(new Paragraph("Average Power Usage: " + df.format(average))); document.add(new Paragraph("Maximum Power Usage: " + df.format(max) + " at " + maxTime.toString())); document.add(new Paragraph("Total Power Usage: " + df.format(total))); //Create a custom date axis to display dates on the X axis DateAxis dateAxis = new DateAxis("Date"); //Make the labels vertical dateAxis.setVerticalTickLabels(true); //Create the power axis NumberAxis powerAxis = new NumberAxis("Power"); //Set both axes to auto range for their values powerAxis.setAutoRange(true); dateAxis.setAutoRange(true); //Create the tooltip generator StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}", new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance()); //Set the renderer StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg, null); //Create the plot XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer); //Create the chart JFreeChart myChart = new JFreeChart(deviceId, JFreeChart.DEFAULT_TITLE_FONT, plot, true); PdfContentByte pcb = writer.getDirectContent(); PdfTemplate tp = pcb.createTemplate(480, 360); Graphics2D g2d = tp.createGraphics(480, 360, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, 480, 360); myChart.draw(g2d, r2d); g2d.dispose(); pcb.addTemplate(tp, 0, 0); document.newPage(); } document.close(); JOptionPane.showMessageDialog(null, "Report Generated."); Desktop.getDesktop().open(outputFile); } catch (FileNotFoundException fnfe) { JOptionPane.showMessageDialog(null, "Unable To Open File For Writing, Make Sure It Is Not Currently Open"); } catch (IOException ex) { Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.unsa.view.MainView.java
License:Creative Commons License
private void DocConverterPDF(File file1) { NPOIFSFileSystem fs = null;/*from w ww . j av a 2 s . c o m*/ com.lowagie.text.Document document = new com.lowagie.text.Document(); try { System.out.println(file1.getAbsolutePath()); fs = new NPOIFSFileSystem(new FileInputStream(file1.getAbsolutePath())); HWPFDocument doc = new HWPFDocument(fs.getRoot()); WordExtractor we = new WordExtractor(doc); String output = file1.getAbsolutePath().substring(0, file1.getAbsolutePath().length() - 3); OutputStream fileout = new FileOutputStream(new File(output + "pdf")); PdfWriter writer = PdfWriter.getInstance(document, fileout); Range range = doc.getRange(); document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); String[] paragraphs = we.getParagraphText(); for (int i = 0; i < paragraphs.length; i++) { org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i); paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", ""); document.add(new Paragraph(paragraphs[i])); } } catch (Exception e) { e.printStackTrace(); } finally { document.close(); } }