List of usage examples for com.lowagie.text Chapter Chapter
public Chapter(String title, int number)
Chapter
. From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java
License:Apache License
/** * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean, * com.orange.atk.results.logger.log.DocumentLogger) *//*ww w . j a v a 2 s.c o m*/ public void dumpInStream(boolean isParseErrorHappened, DocumentLogger dl) { long endTime = new Date().getTime(); // step 1: creation of a document-object Document document = new Document(); PdfWriter writer = null; // step 2: // we create a writer that listens to the document // and directs a PDF-stream to the outputStream try { writer = PdfWriter.getInstance(document, outputStream); } catch (DocumentException e1) { e1.printStackTrace(); return; } writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); // step 3: we open the document document.open(); // step 4: we add a paragraph to the document List<Message> msgLogged = dl.getMsgsLogged(); Paragraph pLoggedMsg = new Paragraph(); // logged messages for (int i = 0; i < msgLogged.size(); i++) { Message msg = msgLogged.get(i); SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS"); String dateString = formatter.format(msg.getTimestamp()); switch (msg.getType()) { case Message.INFO_MSG: pLoggedMsg.add("[" + dateString + "] " + msg.getMessage()); break; case Message.WARN_MSG: pLoggedMsg.add("[" + dateString + "] WARN : " + msg.getMessage() + " at line : " + msg.getLine()); break; case Message.ERROR_MSG: pLoggedMsg.add("[" + dateString + "] ERROR : " + msg.getMessage() + " at line : " + msg.getLine()); break; default: break; } pLoggedMsg.add(Chunk.NEWLINE); } Paragraph pLastLogguedLines = new Paragraph(); int startIndex = msgLogged.size() > 5 ? msgLogged.size() - 5 : 0; for (int i = startIndex; i < msgLogged.size(); i++) { Message m = msgLogged.get(i); switch (m.getType()) { case Message.INFO_MSG: pLastLogguedLines.add("INFO : " + m.getMessage()); break; case Message.WARN_MSG: pLastLogguedLines.add("WARN : " + m.getMessage()); break; case Message.ERROR_MSG: pLastLogguedLines.add("ERROR : " + m.getMessage()); break; default: break; } pLastLogguedLines.add(Chunk.NEWLINE); } // l.setIndentationLeft(40); // Min/Max/Ave values /* * PdfPTable table = new PdfPTable(4); table.addCell(""); * table.addCell("Min"); table.addCell("Max"); table.addCell("Avg"); * * * table.addCell("Battery in %"); table.addCell(String.valueOf(dl * .getMinValueFromList(dl.getplt("BATTERY")))); * table.addCell(String.valueOf(dl * .getMaxValueFromList(dl.getplt("BATTERY")))); * table.addCell(String.valueOf(dl * .getAveValueFromList(dl.getplt("BATTERY")))); * table.addCell("Storage in bytes"); table.addCell(String.valueOf(dl * .getMinValueFromList(dl.getplt("Storage")))); * table.addCell(String.valueOf(dl * .getMaxValueFromList(dl.getplt("Storage")))); * table.addCell(String.valueOf(dl * .getAveValueFromList(dl.getplt("Storage")))); */ document.addTitle("REPORT"); document.addCreationDate(); HeaderFooter headerPage = new HeaderFooter(new Phrase("Execution report"), false); HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - ")); headerPage.setAlignment(Element.ALIGN_CENTER); footerPage.setAlignment(Element.ALIGN_CENTER); document.setHeader(headerPage); document.setFooter(footerPage); // Chapter 1 : Summary // Section 1 : Informations Chunk c = new Chunk("Summary"); c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c.setFont(FONT_PAR_TITLE); Paragraph title1 = new Paragraph(c); title1.setAlignment("CENTER"); title1.setLeading(20); Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph("Informations"); Section section1 = chapter1.addSection(title11); Paragraph pSum = new Paragraph(); pSum.add("Author : " + author); pSum.add(Chunk.NEWLINE); pSum.add("Group : " + group); pSum.add(Chunk.NEWLINE); pSum.add("Script : " + script); pSum.add(Chunk.NEWLINE); SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); pSum.add("Date : " + dateString); pSum.add(Chunk.NEWLINE); pSum.setIndentationLeft(20); section1.add(pSum); section1.add(new Paragraph(Chunk.NEXTPAGE)); Chunk c11 = new Chunk("Executive summary"); c11.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c11.setFont(FONT_PAR_TITLE); Paragraph title12 = new Paragraph(c11); Section section12 = chapter1.addSection(title12); Paragraph pExecSum = new Paragraph(); // pExecSum.add("Value : "); // pExecSum.add(Chunk.NEWLINE); // pExecSum.add(table); pExecSum.add(Chunk.NEWLINE); pExecSum.add("Last logged lines : "); pExecSum.add(Chunk.NEWLINE); pExecSum.add(pLastLogguedLines); pExecSum.add(Chunk.NEWLINE); pExecSum.setIndentationLeft(20); section12.add(pExecSum); try { document.add(chapter1); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // Chapter 2 : Log information Chunk c2 = new Chunk("Log information"); c2.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c2.setFont(FONT_PAR_TITLE); Paragraph title2 = new Paragraph(c2); title2.setAlignment("CENTER"); title2.setLeading(20); Chapter chapter2 = new Chapter(title2, 1); chapter2.setNumberDepth(0); Section section2 = chapter2.addSection("Log"); // Add log information section2.add(pLoggedMsg); section2.add(Chunk.NEWLINE); // section2.add(table); try { document.add(chapter2); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); if (isParseErrorHappened) { document.close(); return; } // Add generated pictures Chunk c3 = new Chunk("Graphics"); c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c3.setFont(FONT_PAR_TITLE); Paragraph p3 = new Paragraph(c3); p3.setAlignment("CENTER"); p3.setLeading(20); Chapter chapter3 = new Chapter(p3, 1); chapter3.setNumberDepth(0); // add current graph Map<String, PlotList> mapint = dl.getMapint(); Set<String> cles = mapint.keySet(); Iterator<String> it = cles.iterator(); while (it.hasNext()) { String cle = (String) it.next(); Paragraph pCPUimg = new Paragraph(cle); Section section31 = chapter3.addSection(pCPUimg); if (new File(dl.getPNGpath(cle)).exists()) { Image jpg1 = null; try { jpg1 = Image.getInstance(dl.getPNGpath(cle)); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (jpg1 == null) { Logger.getLogger(this.getClass()).warn("Error when Creating image jpg1 is null"); return; } // jpg1.setRotationDegrees(270); jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER); section31.add(jpg1); PlotList plotlist = mapint.get(cle); DecimalFormat df = new DecimalFormat("#,###.##"); if (plotlist.getType() == PlotList.TYPE_SUM) { section31.add(new Paragraph("Total : " + df.format(plotlist.getTotal() / plotlist.getScale()) + " " + plotlist.getunit())); } else { // PlotList.TYPE_AVG section31.add(new Paragraph("Average : " + df.format(plotlist.getAverage() / plotlist.getScale()) + " " + plotlist.getunit())); } } section31.add(new Paragraph(Chunk.NEXTPAGE)); } /* * // Section 3.1 : CPU data Paragraph pCPUimg = new * Paragraph("CPU data"); Section section31 = * chapter3.addSection(pCPUimg); if (new * File(dl.getPNGpath("CPU")).exists()) { Image jpg1 = null; try { jpg1 * = Image.getInstance(dl.getPNGpath("CPU")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg1.setRotationDegrees(270); * jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER); * section31.add(jpg1); } section31.add(new Paragraph(Chunk.NEXTPAGE)); * * // Section 3.2 : BAT data Paragraph pBATimg = new * Paragraph("Battery data"); Section section32 = * chapter3.addSection(pBATimg); if (new * File(dl.getPNGpath("BATTERY")).exists()) { Image jpg2 = null; try { * jpg2 = Image.getInstance(dl.getPNGpath("BATTERY")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg2.setRotationDegrees(270); * jpg2.scalePercent(75); jpg2.setAlignment(Element.ALIGN_CENTER); * section32.add(jpg2); } section32.add(new Paragraph(Chunk.NEXTPAGE)); * * // Section 3.3 : MEM data Paragraph pMEMimg = new * Paragraph("Memory data"); Section section33 = * chapter3.addSection(pMEMimg); if (new * File(dl.getPNGpath("MEMORY")).exists()) { * * Image jpg3 = null; try { jpg3 = * Image.getInstance(dl.getPNGpath("MEMORY")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg3.setRotationDegrees(270); * jpg3.scalePercent(75); jpg3.setAlignment(Element.ALIGN_CENTER); * section33.add(jpg3); } section33.add(new Paragraph(Chunk.NEXTPAGE)); * * // Section 3.4 : STO data Paragraph pSTOimg = new * Paragraph("Storage data"); Section section34 = * chapter3.addSection(pSTOimg); if (new * File(dl.getPNGpath("Storage")).exists()) { * * Image jpg4 = null; try { jpg4 = * Image.getInstance(dl.getPNGpath("Storage")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg4.setRotationDegrees(270); * jpg4.scalePercent(75); jpg4.setAlignment(Element.ALIGN_CENTER); * section34.add(jpg4); } * * * // Section 3.5 : Network connection //Paragraph pNetworkimg = new * Paragraph("Network QoS data"); //Section section35 = * chapter3.addSection(pNetworkimg); // if (new * File(dl.getNetworkPNGfile()).exists()) { * * // Image jpg5 = null; // try { // jpg5 = * Image.getInstance(dl.getNetworkPNGfile()); // } catch * (BadElementException e) { // e.printStackTrace(); // } catch * (MalformedURLException e) { // e.printStackTrace(); // } catch * (IOException e) { // e.printStackTrace(); // } * //jpg4.setRotationDegrees(270); // jpg5.scalePercent(75); // * jpg5.setAlignment(Element.ALIGN_CENTER); // section35.add(jpg5); //} */ try { document.add(chapter3); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // if (isTableEnabled) { // // Add tables filled with measurement // // Chapter 4 : Measurement tables // Chunk c4 = new Chunk("Statistics tables"); // c4.setBackground(new Color(0xFF, 0x66, 0x00), 200, 3f, 200f, 3f); // c4.setFont(FontFactory.getFont(BaseFont.HELVETICA, // BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, 16)); // Paragraph title4 = new Paragraph(c4); // title4.setAlignment("CENTER"); // title4.setLeading(20); // Chapter chapter4 = new Chapter(title4, 1); // chapter4.setNumberDepth(0); // // // Section 4.1 : Battery value // Paragraph titleSection41 = new Paragraph("Battery value"); // Section section41 = chapter4.addSection(titleSection41); // Paragraph pBatList = new Paragraph(); // pBatList.add(Chunk.NEWLINE); // pBatList.add(createPDFTableFromList(dl // .getList(DocumentLogger.BATTERY), "Battery")); // pBatList.setAlignment("CENTER"); // section41.add(pBatList); // // // Section 4.2 : CPU value // Paragraph titleSection42 = new Paragraph("CPU value"); // Section section42 = chapter4.addSection(titleSection42); // Paragraph pCPUList = new Paragraph(); // pCPUList.add(Chunk.NEWLINE); // pCPUList.add(createPDFTableFromList(dl.getList(DocumentLogger.CPU), // "CPU")); // pCPUList.setAlignment("CENTER"); // section42.add(pCPUList); // // // Section 4.3 : Memory value // Paragraph titleSection43 = new Paragraph("Memory value"); // Section section43 = chapter4.addSection(titleSection43); // Paragraph pMemList = new Paragraph(); // pMemList.add(Chunk.NEWLINE); // pMemList.add(createPDFTableFromList(dl // .getList(DocumentLogger.MEMORY), "Memory")); // pMemList.setAlignment("CENTER"); // section43.add(pMemList); // // // Section 4.4 : Storage value // Paragraph titleSection44 = new Paragraph("Storage value"); // Section section44 = chapter4.addSection(titleSection44); // Paragraph pStoList = new Paragraph(); // pStoList.add(Chunk.NEWLINE); // pStoList.add(createPDFTableFromList(dl // .getList(DocumentLogger.STORAGE), "Storage")); // pStoList.setAlignment("CENTER"); // section44.add(pStoList); // // try { // document.add(chapter4); // } catch (DocumentException e) { // e.printStackTrace(); // } // } // step 5: we close the document document.close(); createHTMLFile(dl); }
From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java
License:Apache License
public void dumpInStreamactionlogger(boolean isParseErrorHappened, ActionsLogger actionlog, DocumentLogger dl) { long endTime = new Date().getTime(); // step 1: creation of a document-object Document document = new Document(); PdfWriter writer = null;/* w w w . j a v a 2 s . co m*/ Vector VectAction = actionlog.getActions(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to the outputStream try { writer = PdfWriter.getInstance(document, outputStream); } catch (DocumentException e1) { e1.printStackTrace(); return; } writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); // step 3: we open the document document.open(); // step 4: we add a paragraph to the document Paragraph pLoggedMsg = new Paragraph(); // logged messages for (int i = 0; i < VectAction.size(); i++) { Action action = (Action) VectAction.get(i); SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS"); SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS"); String dateString = spf.format(action.getStartTime()); pLoggedMsg.add("[" + dateString + "] : " + action.getActionName()); pLoggedMsg.add(Chunk.NEWLINE); } Paragraph pLastLogguedLines = new Paragraph(); int startIndex = VectAction.size() > 5 ? VectAction.size() - 5 : 0; for (int i = startIndex; i < VectAction.size(); i++) { Action action = (Action) VectAction.get(i); // SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS"); SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS"); String dateString = spf.format(action.getStartTime()); pLastLogguedLines.add("[" + dateString + "] : " + action.getActionName()); pLastLogguedLines.add(Chunk.NEWLINE); } document.addTitle("REPORT"); document.addCreationDate(); HeaderFooter headerPage = new HeaderFooter(new Phrase("Execution report"), false); HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - ")); headerPage.setAlignment(Element.ALIGN_CENTER); footerPage.setAlignment(Element.ALIGN_CENTER); document.setHeader(headerPage); document.setFooter(footerPage); // Chapter 1 : Summary // Section 1 : Informations Chunk c = new Chunk("Summary"); c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c.setFont(FONT_PAR_TITLE); Paragraph title1 = new Paragraph(c); title1.setAlignment("CENTER"); title1.setLeading(20); Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph("Informations"); Section section1 = chapter1.addSection(title11); Paragraph pSum = new Paragraph(); pSum.add("Author : " + author); pSum.add(Chunk.NEWLINE); pSum.add("Group : " + group); pSum.add(Chunk.NEWLINE); pSum.add("Script : " + script); pSum.add(Chunk.NEWLINE); SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); pSum.add("Date : " + dateString); pSum.add(Chunk.NEWLINE); pSum.setIndentationLeft(20); section1.add(pSum); section1.add(new Paragraph(Chunk.NEXTPAGE)); Chunk c11 = new Chunk("Executive summary"); c11.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c11.setFont(FONT_PAR_TITLE); Paragraph title12 = new Paragraph(c11); Section section12 = chapter1.addSection(title12); Paragraph pExecSum = new Paragraph(); // pExecSum.add("Value : "); // pExecSum.add(Chunk.NEWLINE); // pExecSum.add(table); pExecSum.add(Chunk.NEWLINE); pExecSum.add("Last logged lines : "); pExecSum.add(Chunk.NEWLINE); pExecSum.add(pLastLogguedLines); pExecSum.add(Chunk.NEWLINE); pExecSum.setIndentationLeft(20); section12.add(pExecSum); try { document.add(chapter1); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // Chapter 2 : Log information Chunk c2 = new Chunk("Log information"); c2.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c2.setFont(FONT_PAR_TITLE); Paragraph title2 = new Paragraph(c2); title2.setAlignment("CENTER"); title2.setLeading(20); Chapter chapter2 = new Chapter(title2, 1); chapter2.setNumberDepth(0); Section section2 = chapter2.addSection("Log"); // Add log information section2.add(pLoggedMsg); section2.add(Chunk.NEWLINE); // section2.add(table); try { document.add(chapter2); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); if (isParseErrorHappened) { document.close(); return; } // Add generated pictures Chunk c3 = new Chunk("Graphics"); c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c3.setFont(FONT_PAR_TITLE); Paragraph p3 = new Paragraph(c3); p3.setAlignment("CENTER"); p3.setLeading(20); Chapter chapter3 = new Chapter(p3, 1); chapter3.setNumberDepth(0); // add current graph Map<String, PlotList> mapint = dl.getMapint(); Set<String> cles = mapint.keySet(); Iterator<String> it = cles.iterator(); while (it.hasNext()) { String cle = (String) it.next(); Paragraph pCPUimg = new Paragraph(cle); Section section31 = chapter3.addSection(pCPUimg); if (new File(dl.getPNGpath(cle)).exists()) { Image jpg1 = null; try { jpg1 = Image.getInstance(dl.getPNGpath(cle)); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (jpg1 == null) { Logger.getLogger(this.getClass()).warn("Error when Creating image jpg1 is null"); return; } // jpg1.setRotationDegrees(270); jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER); section31.add(jpg1); } section31.add(new Paragraph(Chunk.NEXTPAGE)); } try { document.add(chapter3); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); document.close(); createHTMLFileactionlog(actionlog, dl); }
From source file:com.parakhcomputer.util.pdf.FirstPdf.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("First Chapter", catFont); anchor.setName("First Chapter"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1", subFont); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategory 2", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragraph 1")); subCatPart.add(new Paragraph("Paragraph 2")); subCatPart.add(new Paragraph("Paragraph 3")); // Add a list createList(subCatPart);//from w w w . j av a 2 s. c o m Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // Add a table createTable(subCatPart); // Now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Second Chapter", catFont); anchor.setName("Second Chapter"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Subcategory", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("This is a very important message")); // Now add all this to the document document.add(catPart); }
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 2 s.com 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.almanach.control.AlmanachPdfGenerator.java
License:Open Source License
static public void buildPdf(String name, AlmanachSessionController almanach, String mode) throws AlmanachRuntimeException { try {//from w w w .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); } }
From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java
License:Open Source License
/** * Method declaration//from w w w.ja v a 2 s.com * @param name * @param completePubList * @param langue * @throws NewsEditoException * @see */ public static void generatePubList(String name, Collection<CompletePublication> completePubList, String langue) throws NewsEditoException { SilverTrace.info("NewsEdito", "PdfGenerator.generatePubList", "NewsEdito.MSG_ENTRY_METHOD", "Pdf name = " + name); try { CompletePublication first = completePubList.iterator().next(); String fileName = FileRepositoryManager.getTemporaryPath( first.getPublicationDetail().getPK().getSpace(), first.getPublicationDetail().getPK().getComponentName()) + name; ResourceLocator message = new ResourceLocator( "com.stratelia.webactiv.newsEdito.multilang.newsEditoBundle", langue); // creation of the document with a certain size and certain margins Document document = new Document(PageSize.A4, 50, 50, 50, 50); // we add some meta information to the document document.addAuthor("Generateur de PDF Silverpeas"); document.addSubject("Compilation de publications Silverpeas"); document.addCreationDate(); PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); createFirstPage(document, langue); HeaderFooter header = new HeaderFooter(new Phrase(message.getString("publicationCompilation")), false); HeaderFooter footer = new HeaderFooter(new Phrase("Page "), new Phrase(".")); footer.setAlignment(Element.ALIGN_CENTER); document.setHeader(header); document.setFooter(footer); document.newPage(); Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255)); Paragraph cTitle = new Paragraph(message.getString("listPublication"), titleFont); Chapter chapter = new Chapter(cTitle, 1); Iterator<CompletePublication> i = completePubList.iterator(); CompletePublication complete = null; while (i.hasNext()) { complete = i.next(); addPublication(chapter, complete); } document.add(chapter); document.close(); } catch (Exception e) { throw new NewsEditoException("PdfGenerator.generatePubList", NewsEditoException.WARNING, "NewsEdito.EX_PROBLEM_TO_GENERATE_PUBLI_LIST", e); } }
From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java
License:Open Source License
/** * Method declaration/* ww w. ja v a2s . c o m*/ * @param document * @param title * @param titleCount * @param publicationBm * @return * @throws NewsEditoException * @see */ public static Section addTitle(Document document, NodeDetail title, int titleCount, PublicationBm publicationBm) throws NewsEditoException { // we define some fonts Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255)); Paragraph cTitle = new Paragraph(title.getName(), titleFont); Chapter chapter = new Chapter(cTitle, titleCount); if (title.getDescription() != null) { chapter.add(new Paragraph(title.getDescription())); } try { addPublications(chapter, title, publicationBm); document.add(chapter); } catch (Exception e) { throw new NewsEditoException("PdfGenerator.addTitle", NewsEditoException.WARNING, "NewsEdito.EX_NO_TITLE_ADDED", e); } return chapter; }
From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java
License:Open Source License
/** * Method declaration//from w w w . j av a 2 s . c om * @param document * @param archiveDetail * @param publicationBm * @param langue * @see */ public static void addEditorial(Document document, NodeDetail archiveDetail, PublicationBm publicationBm, String langue) throws NewsEditoException { SilverTrace.info("NewsEdito", "PdfGenerator.addEditorial", "NewsEdito.MSG_ENTRY_METHOD"); try { ResourceLocator message = new ResourceLocator( "com.stratelia.webactiv.newsEdito.multilang.newsEditoBundle", langue); Collection<PublicationDetail> pubList = publicationBm.getDetailsByFatherPK(archiveDetail.getNodePK()); Iterator<PublicationDetail> i = pubList.iterator(); if (i.hasNext()) { try { Font publicationFont = new Font(Font.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64)); Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255)); Paragraph cTitle = new Paragraph(message.getString("editorial"), titleFont); Chapter chapter = new Chapter(cTitle, 0); chapter.setNumberDepth(0); PublicationDetail detail = null; Paragraph name = null; Section subsection = null; Image img = null; while (i.hasNext()) { detail = i.next(); name = new Paragraph(detail.getName(), publicationFont); subsection = chapter.addSection(name, 0); subsection.setNumberDepth(0); if (detail.getDescription() != null) { subsection.add(new Paragraph(detail.getDescription())); } if (detail.getImage() != null) { String imagePath = FileRepositoryManager .getAbsolutePath(detail.getPK().getComponentName()) + getImagePath() + File.separator + detail.getImage(); try { SilverTrace.info("NewsEdito", "PDFGenerator.addEditorial", "root.MSG_PARAM_VALUE", "imagePath = " + imagePath); img = Image.getInstance(imagePath); } catch (Exception e) { SilverTrace.info("NewsEdito", "PDFGenerator.addEditorial", "NewsEdito.MSG_CANNOT_RETRIEVE_IMAGE", "imagePath = " + imagePath); } if (img == null) { SilverTrace.info("NewsEdito", "PdfGenerator.addEditorial", "NewsEdito.MSG_CANNOT_RETRIEVE_IMAGE"); } else { subsection.add(img); } } } document.add(chapter); } catch (DocumentException de) { SilverTrace.warn("NewsEdito", "PdfGenerator.addEditorial", "NewsEdito.EX_NO_EDITO_ADDED"); } } } catch (Exception e) { throw new NewsEditoException("PdfGenerator.addEditorial", NewsEditoException.WARNING, "NewsEdito.EX_PROBLEM_TO_ADD_EDITO", e); } }
From source file:include.nseer_cookie.MakePdf.java
License:Open Source License
public void make(String database, String tablename, String sql1, String sql2, String filename, int everypage, HttpSession session) {/* w ww . ja v a 2s. co m*/ try { nseer_db aaa = new nseer_db(database); nseer_db demo_db = new nseer_db(database); ServletContext context = session.getServletContext(); String path = context.getRealPath("/"); Masking reader = new Masking(configFile); Vector columnNames = new Vector(); Vector tables = reader.getTableNicks(); Iterator loop = tables.iterator(); while (loop.hasNext()) { String tablenick = (String) loop.next(); columnNames = reader.getColumnNames(tablenick); } int cpage = 1; //? int spage = 1; int ipage = everypage; String pagesql = sql1; //? ResultSet pagers = demo_db.executeQuery(pagesql); pagers.next(); int allCol = pagers.getInt("A"); allpage = (int) Math.ceil((allCol + ipage - 1) / ipage); // for (int m = 1; m <= allpage; m++) { spage = (m - 1) * ipage; String sql = sql2 + " limit " + spage + "," + ipage; ResultSet bbb = aaa.executeQuery(sql); //ResultSetMetaData tt=bbb.getMetaData(); // int b = columnNames.size(); // int a = 0; while (bbb.next()) { a++; } // bbb.first(); // ?? Rectangle rectPageSize = new Rectangle(PageSize.A4);// rectPageSize = rectPageSize.rotate(); Document document = new Document(rectPageSize, 20, 20, 20, 20); //? Document PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename + m + ".pdf")); //?PDF?? document.open(); // BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); //? com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 8, com.lowagie.text.Font.NORMAL); // Paragraph title1 = new Paragraph("nseer ERP", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC)); Chapter chapter1 = new Chapter(title1, 1); // ? chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph(tablename, FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)); Section section1 = chapter1.addSection(title11); //? Table t = new Table(b, a); // ? t.setPadding(1); // t.setSpacing(0); // ? t.setBorderWidth(1); // do { // // for (int k = 0; k < b; k++) { // Cell cell = new Cell( new Paragraph(bbb.getString((String) columnNames.elementAt(k)), FontChinese)); //? // t.addCell(cell); // ? // } // } while (bbb.next()); // section1.add(t); // document.add(chapter1); // document.close(); } // ? } catch (Exception pp) { pp.printStackTrace(); } }
From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java
License:Open Source License
private static void addContent(Document document, List<EventoBean> eventi, IEventiService eventiService) throws UtilsException, DocumentException { Anchor anchor = new Anchor("Eventi Selezionati", catFont); anchor.setName("Eventi Selezionati"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); for (EventoBean eventoBean : eventi) { Evento evento = eventoBean.getDTO(); Paragraph subPara = new Paragraph("Evento Id[" + evento.getId() + "]", subFont); Section subCatPart = catPart.addSection(subPara); addEmptyLine(subCatPart, 1);/* w ww .jav a2 s. c om*/ createEventoTable(subCatPart, evento); addEmptyLine(subCatPart, 1); Infospcoop infospcoop = eventoBean.getInfospcoop() != null ? eventoBean.getInfospcoop().getDTO() : null; if (infospcoop != null) { // if(evento.getCategoria().equals(Categoria.INTERFACCIA) && evento.getIdEgov()!= null){ // Infospcoop infospcoop = eventiService.getInfospcoopByIdEgov(evento.getIdEgov()); Paragraph infoParg = new Paragraph("Infospcoop", subFont); subCatPart.addSection(infoParg); addEmptyLine(subCatPart, 1); createInfospcoopTable(subCatPart, infospcoop); //subCatPart.add(new Paragraph(infospcoop.toXml())); } addEmptyLine(subCatPart, 1); catPart.newPage(); } // now add all this to the document document.add(catPart); }