List of usage examples for com.lowagie.text Anchor setName
public void setName(String name)
Anchor
. From source file: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 little list createList(subCatPart);//ww w .j a va 2 s . c o m // Add a small table createTable(subCatPart); // Now a small table // 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.amphisoft.epub2pdf.content.XhtmlHandler.java
License:Open Source License
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { /*/*from ww w .jav a2 s . c o m*/ if("ol".equals(qName) || "ul".equals(qName) || "li".equals(qName)) { System.err.print(qName + " "); } */ currentSaxElemId = saxElemIdCounter; Map<String, String> attrMap = new HashMap<String, String>(); // parse attributes for (int ai = 0; ai < attributes.getLength(); ai++) { attrMap.put(attributes.getQName(ai), attributes.getValue(ai)); } String idAttr = attrMap.get("id"); if (idAttr == null) { idAttr = ""; } String className = attrMap.get("class"); if (className == null) { className = ""; } SaxElement sE = new SaxElement(qName, saxElemIdCounter++, className, idAttr, currentITextStyle); //printlnerr("startElement: " + sE.toString()); saxElementStack.push(sE); try { if (attrMap.get("class") != null) { String[] elemClasses = attrMap.get("class").split(" "); for (String eClass : elemClasses) { StyleSpecText classTextStyles = styleMap.getTextStyleSpecFor(qName, eClass); if (classTextStyles != null) { sE.applyTextStyles(classTextStyles); } } } if (attrMap.get("style") != null) { // TODO this needs more thought, and careful tracking of which tags are still open, etc. //String styleSource = attrMap.get("style"); //CssStyleMap styleTagStyles = cssParser.getStylesFromStyleTag(styleSource); // ... } if (sE.textStyles == null) { try { int stackSize = saxElementStack.size(); if (stackSize > 1) { SaxElement enclosingElement = saxElementStack.elementAt(stackSize - 2); StyleSpecText enclosingSST = enclosingElement.textStyles; if (enclosingSST != null) sE.applyTextStyles(enclosingSST); } } catch (Exception e) { } } StyleSpecText currentTextStyles = sE.textStyles; if (currentTextStyles != null) { if (currentTextStyles.isBold()) { currentITextStyle |= Font.BOLD; } if (currentTextStyles.isItalic()) { currentITextStyle |= Font.ITALIC; } } //System.err.println("PUSH -> " + saxElementStack); previousTag = currentTag; currentTag = qName; if (document.isOpen()) { if (XhtmlTags.NEWLINE.equals(qName)) { if (stack.size() > 0) { TextElementArray currentTEA = (TextElementArray) stack.peek(); currentTEA.add(Chunk.NEWLINE); } else if (specialParagraph != null) { specialParagraph.add(Chunk.NEWLINE); } } updateStack(); String xmlElementId = attrMap.get("id"); if (XhtmlTags.ANCHOR.equals(qName)) { //concession to nonconformists... if (xmlElementId == null) { xmlElementId = attrMap.get("name"); } Anchor anchor = textFactory.newAnchor(); String ref = attrMap.get(XhtmlTags.REFERENCE); if (ref != null) { int aNameStartIdx = ref.lastIndexOf("#") + 1; ref = ref.substring(aNameStartIdx); anchor.setReference(ref); } if (xmlElementId != null) { anchor.setName(xmlElementId); } pushToStack(anchor); } else { if (xmlElementId != null) { //flushStack(); Anchor dest = textFactory.newAnchor(); dest.setName(xmlElementId); pushToStack(dest); //flushStack(); } for (int i = 0; i < 6; i++) { if (XhtmlTags.H[i].equals(qName)) { flushStack(); freshParagraph = true; currentITextStyle |= Font.BOLD; specialParagraph = textFactory.newHeadline(i + 1); return; } } if ("blockquote".equals(qName)) { flushStack(); freshParagraph = true; Paragraph p = textFactory.newParagraph(); p.setIndentationLeft(50); p.setIndentationRight(20); p.setAlignment(defaultAlignment); pushToStack(p); } else if (XhtmlTags.PARAGRAPH.equals(qName)) { flushStack(); freshParagraph = true; Paragraph p = textFactory.newParagraph(); pushToStack(p); } else if (XhtmlTags.DIV.equals(qName)) { if (stack.size() > 0 && stack.peek().getChunks().size() > 0) { flushStack(); } if (stack.size() == 0) { Paragraph brandNewParagraph = textFactory.newParagraph(); pushToStack(brandNewParagraph); freshParagraph = true; } } else if (XhtmlTags.PRE.equals(qName)) { flushStack(); freshParagraph = true; Paragraph p = textFactory.newParagraphPre(); pushToStack(p); } else if (XhtmlTags.ORDEREDLIST.equals(qName)) { flushStack(); List oList = new List(List.ORDERED, 10); pushToStack(oList); } else if (XhtmlTags.UNORDEREDLIST.equals(qName)) { flushStack(); List uList = new List(List.UNORDERED, 10); pushToStack(uList); } else if (XhtmlTags.LISTITEM.equals(qName)) { freshParagraph = true; ListItem listItem = new ListItem(); pushToStack(listItem); } else if (XhtmlTags.IMAGE.equals(qName)) { handleImage(attributes); } else if (qName != null && qName.endsWith("image")) { handleSvgImage(attributes); } else if (XhtmlTags.LINK.equals(qName)) { // if it's a stylesheet, parse it & update current-style if ("stylesheet".equals(attrMap.get("rel")) && "text/css".equals(attrMap.get("type")) && attrMap.get("href") != null) { String cssHref = xhtmlDir.getAbsoluteFile().toURI().toString() + attrMap.get("href"); CssStyleMap stylesFromLink = cssParser.getStylesFromFileURI(cssHref); if (stylesFromLink != null) { styleMap.updateWith(stylesFromLink); } } } else if (XhtmlTags.STYLE.equals(qName)) { inStyleTag = true; } else if (XhtmlTags.EM.equals(qName) || "I".equals(qName.toUpperCase())) { currentITextStyle |= Font.ITALIC; } else if (XhtmlTags.STRONG.equals(currentTag) || "B".equals(qName.toUpperCase())) { currentITextStyle |= Font.BOLD; } } } else if (XhtmlTags.BODY.equals(qName)) { document.open(); freshParagraph = true; } } catch (Exception e) { e.printStackTrace(); } //printlnerr("leaving startElement " + localName + "; stack: " + stackStatus()); }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void startChapter(String pStrChapterTitle) { Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());// w w w . jav a 2s . c o m lFont.setStyle(Font.BOLD); Anchor anchor = new Anchor(pStrChapterTitle, lFont); anchor.setName(pStrChapterTitle); mChapter = new Chapter(new Paragraph(anchor), ++mIntChapterPosition); addEmptyLines(1); }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void startSection(String pStrSectionTitle) { Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());/*from w ww . j av a 2 s .c o m*/ lFont.setStyle(Font.ITALIC); Anchor anchor = new Anchor(pStrSectionTitle, lFont); anchor.setName(pStrSectionTitle); mSection = mChapter.addSection(new Paragraph(anchor)); }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void startSubSection(String pStrSubSectionTitle) { Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());/*from ww w .j a v a 2s . c o m*/ Anchor anchor = new Anchor(pStrSubSectionTitle, lFont); anchor.setName(pStrSubSectionTitle); addEmptyLines(1); mSubSection = mSection.addSection(new Paragraph(anchor)); addEmptyLines(1); }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static void appendWiki(WikiPDFContext context, Wiki currentWiki, Document document, Connection db, ArrayList<Integer> wikiListDone) throws SQLException { LOG.debug("appendWiki-> " + currentWiki.getSubject()); // Context Objects Project project = context.getProject(); WikiExportBean exportBean = context.getExportBean(); // Track the wikis to get appended to the output ArrayList<Integer> wikiListTodo = new ArrayList<Integer>(); try {/* www . j av a 2s .c o m*/ // Output the name of the Wiki boolean hasTitle = StringUtils.hasText(currentWiki.getSubject()); if (hasTitle) { Anchor wikiAnchor = new Anchor(currentWiki.getSubject(), wikiFont); wikiAnchor.setName(currentWiki.getSubject().toLowerCase()); LOG.debug("Add anchor: " + currentWiki.getSubject().toLowerCase()); document.add(wikiAnchor); LOG.debug("document.add(wikiAnchor)"); } // Output the wiki content parseContent(context, currentWiki, currentWiki.getContent(), document, null, db, wikiListTodo, wikiListDone, 0f); wikiListDone.add(currentWiki.getId()); // See if any linked wikis should be appended if (exportBean.getFollowLinks() && wikiListTodo.size() > 0) { Iterator i = wikiListTodo.iterator(); while (i.hasNext()) { Integer id = (Integer) i.next(); if (id > -1 && !wikiListDone.contains(id)) { Wiki subwiki = new Wiki(db, id); document.add(Chunk.NEXTPAGE); appendWiki(context, subwiki, document, db, wikiListDone); } //i.remove(); } } } catch (Exception e) { LOG.error("appendWiki", e); } }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static boolean parseLine(WikiPDFContext context, String line, Paragraph main, Connection db, ArrayList<Integer> wikiListTodo, float cellWidth, PdfPCell cell) throws Exception { LOG.debug("PARSING LINE: " + line); // Context Objects Project project = context.getProject(); WikiExportBean exportBean = context.getExportBean(); HashMap<String, ImageInfo> imageList = context.getImageList(); String fileLibrary = context.getFileLibrary(); boolean needsCRLF = true; boolean bold = false; boolean italic = false; boolean bolditalic = false; StringBuffer subject = new StringBuffer(); StringBuffer data = new StringBuffer(); int linkL = 0; int linkR = 0; int attr = 0; int underlineAttr = 0; // parse characters for (int i = 0; i < line.length(); i++) { char c1 = line.charAt(i); String c = String.valueOf(c1); // False attr/links if (!"'".equals(c) && attr == 1) { data.append("'").append(c); attr = 0;/*from w w w . j a va 2s. co m*/ continue; } if (!"_".equals(c) && underlineAttr == 1) { data.append("_").append(c); underlineAttr = 0; continue; } if (!"[".equals(c) && linkL == 1) { data.append("[").append(c); linkL = 0; continue; } if (!"]".equals(c) && linkR == 1) { data.append("]").append(c); linkR = 0; continue; } // Links if ("[".equals(c)) { ++linkL; continue; } if ("]".equals(c)) { ++linkR; if (linkL == 2 && linkR == 2) { LOG.debug("main.add(new Chunk(data.toString()))"); main.add(new Chunk(data.toString())); data.setLength(0); // Different type of links... String link = subject.toString().trim(); if (link.startsWith("Image:") || link.startsWith("image:")) { // @note From WikiImageLink.java String image = link.substring(6); String title = null; int frame = -1; int thumbnail = -1; int left = -1; int right = -1; int center = -1; int none = -1; int imageLink = -1; int alt = -1; if (image.indexOf("|") > 0) { // the image is first image = image.substring(0, image.indexOf("|")); // any directives are next frame = link.indexOf("|frame"); thumbnail = link.indexOf("|thumb"); left = link.indexOf("|left"); right = link.indexOf("|right"); center = link.indexOf("|center"); none = link.indexOf("|none"); imageLink = link.indexOf("|link="); alt = link.indexOf("|alt="); // the optional caption is last int last = link.lastIndexOf("|"); if (last > frame && last > thumbnail && last > left && last > right && last > center && last > none && last > imageLink && last > alt) { title = link.substring(last + 1); } } //A picture, including alternate text: //[[Image:Wiki.png|The logo for this Wiki]] //You can put the image in a frame with a caption: //[[Image:Wiki.png|frame|The logo for this Wiki]] // Access some image details int width = 0; int height = 0; ImageInfo imageInfo = imageList.get(image + (thumbnail > -1 ? "-TH" : "")); if (imageInfo != null) { width = imageInfo.getWidth(); height = imageInfo.getHeight(); } // Alt String altText = null; if (alt > -1) { int startIndex = alt + 4; int endIndex = link.indexOf("|", startIndex); if (endIndex == -1) { endIndex = link.length(); } altText = link.substring(startIndex, endIndex); } // Looks like the image needs a link (which is always last) String url = null; if (imageLink > -1) { // Get the entered link int startIndex = imageLink + 6; int endIndex = link.length(); String href = link.substring(startIndex, endIndex); // Treat as a wikiLink to validate and to create a proper url WikiLink wikiLink = new WikiLink(project.getId(), (altText != null ? href + " " + altText : href)); url = wikiLink.getUrl(""); if (!url.startsWith("http://") && !url.startsWith("https://")) { // @todo Use a local link // @todo Use an external link } } // Determine if local or external image if ((image.startsWith("http://") || image.startsWith("https://"))) { // retrieve external image String imageUrl = null; try { URL imageURL = new URL(image); imageUrl = image; } catch (Exception e) { } } else { // local image try { // @todo image alignment and links Image thisImage = Image.getInstance( getImageFilename(db, fileLibrary, project, image, (thumbnail > -1))); LOG.debug("Drawing image for area: " + cellWidth); if (cellWidth > 0f) { LOG.debug(" Image is embedded in cell"); // Guess the size of the cell float cellPixels = (500f * (cellWidth / 100f)); if (cellPixels > 0f && (float) width > cellPixels) { // Shrink image to fit the cell LOG.debug(" Scaling to fit"); thisImage.scaleToFit(cellPixels, 500f); } else { // Align image to left instead of scaling it to fit thisImage.setAlignment(Image.LEFT); } LOG.debug("cell.addElement(thisImage)"); cell.addElement(thisImage); } else { LOG.debug(" Image is inline"); if (width > 500) { LOG.debug(" Scaling to fit"); thisImage.scaleToFit(500f, 500f); } LOG.debug("main.add(thisImage)"); main.add(thisImage); } // thisImage.setAlignment(); // thisImage.Alignment = Image.TEXTWRAP | Image.ALIGN_RIGHT; // main.add(thisImage); } catch (FileNotFoundException fnfe) { LOG.warn("WikiPDFUtils-> Image was not found in the FileLibrary (" + getImageFilename(db, fileLibrary, project, image, (thumbnail > -1)) + ")... will continue."); } } /* if (frame > -1 || thumbnail > -1) { sb.append("</div>"); sb.append("<div id=\"caption\" style=\"margin-bottom: 5px; margin-left: 5px; margin-right: 5px; text-align: left;\">"); } if (thumbnail > -1) { sb.append("<div style=\"float:right\"><a target=\"_blank\" href=\"ProjectManagementWiki.do?command=Img&pid=" + wiki.getProjectId() + "&subject=" + StringUtils.replace(StringUtils.jsEscape(image), "%20", "+") + "\"><img src=\"images/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"Enlarge\" border=\"0\" /></a></div>"); } if (frame > -1 || thumbnail > -1) { if (title != null) { sb.append(StringUtils.toHtml(title)); } sb.append( " </div>\n" + "</div>"); } */ /* if (none > -1) { sb.append("<br clear=\"all\">"); } */ if (i + 1 == line.length() && (right > -1 || left > -1) || none > -1) { needsCRLF = false; } } else { // This is most likely a Wiki link String title = subject.toString().trim(); if (link.indexOf("|") > 0) { link = link.substring(0, link.indexOf("|")).trim(); title = title.substring(title.indexOf("|") + 1); } if (link.indexOf("http://") > -1 || link.indexOf("https://") > -1) { String label = link; if (link.indexOf(" ") > 0) { label = link.substring(link.indexOf(" ") + 1); link = link.substring(0, link.indexOf(" ")); } Anchor anchor1 = new Anchor(label, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor1.setReference(link); anchor1.setName("top"); main.add(anchor1); } else { // Place a wiki link if (exportBean.getFollowLinks()) { // See if target link exists before creating a link to it int linkedWikiId = -1; if (StringUtils.hasText(title) && !title.startsWith("|")) { Wiki subwiki = WikiList.queryBySubject(db, title, project.getId()); if (subwiki.getId() > -1) { linkedWikiId = subwiki.getId(); } } // Display the linked item if (linkedWikiId > -1) { // Display as an anchor Anchor linkToWiki = new Anchor(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); linkToWiki.setReference("#" + title.toLowerCase()); LOG.debug("Link to: #" + title.toLowerCase()); main.add(linkToWiki); LOG.debug(" main.add(linkToWiki)"); // main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))).setLocalGoto(link)); // Add this wiki to the to do list... if (!wikiListTodo.contains(linkedWikiId)) { wikiListTodo.add(linkedWikiId); } } else { // Display without the link main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)))); } } else { // Not following links, so display... perhaps as an external link someday main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)))); } } } subject.setLength(0); linkL = 0; linkR = 0; } continue; } if (!"[".equals(c) && linkL == 2 && !"]".equals(c)) { subject.append(c); continue; } // Attribute properties if ("'".equals(c)) { ++attr; continue; } if (!"'".equals(c) && attr > 1) { if (attr == 2) { if (!italic) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); italic = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC, new Color(0, 0, 0)))); data.setLength(0); italic = false; } attr = 0; continue; } if (attr == 3) { if (!bold) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); bold = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); data.setLength(0); bold = false; } attr = 0; continue; } if (attr == 5) { if (!bolditalic) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); bolditalic = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, new Color(0, 0, 0)))); data.setLength(0); bolditalic = false; } attr = 0; continue; } } data.append(c); } for (int x = 0; x < linkR; x++) { data.append("]"); } for (int x = 0; x < linkL; x++) { data.append("["); } if (attr == 1) { data.append("'"); } if (italic) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC, new Color(0, 0, 0)))); } else if (bold) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); } else if (bolditalic) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, new Color(0, 0, 0)))); } else { main.add(new Chunk(data.toString())); } data.setLength(0); return needsCRLF; }
From source file:com.exam.server.ConvertPDF.java
private static void addContent(Document document, ArrayList<DeviceDTO> input) throws DocumentException { Anchor anchor = new Anchor("", catFont); anchor.setName("User Report"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("", 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); // Paragraph paragraph = new Paragraph(); // addEmptyLine(paragraph, 5); // subCatPart.add(paragraph); // add a table createTable(subCatPart, input);/*from w w w . ja v a2s . co m*/ // 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); document.newPage(); }
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);// w w w . j a v a2 s .com 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.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 ava 2 s . c om*/ * @param job The job to include in the document. * * @throws DocumentException If a problem occurs while writing the contents. */ private void writeJob(Document document, Job job) throws DocumentException { Anchor anchor = new Anchor("Job " + job.getJobID(), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK)); anchor.setName(job.getJobID()); Paragraph p = new Paragraph(anchor); document.add(p); // Write the general information to the document. p = new Paragraph("General Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); writeTableCell(table, "Job ID"); writeTableCell(table, job.getJobID()); String optimizingJobID = job.getOptimizingJobID(); if ((optimizingJobID != null) && (optimizingJobID.length() > 0)) { writeTableCell(table, "Optimizing Job ID"); writeTableCell(table, optimizingJobID); } String descriptionStr = job.getJobDescription(); if ((descriptionStr == null) || (descriptionStr.length() == 0)) { descriptionStr = "(Not Specified)"; } writeTableCell(table, "Job Description"); writeTableCell(table, descriptionStr); writeTableCell(table, "Job Type"); writeTableCell(table, job.getJobClassName()); writeTableCell(table, "Job Class"); writeTableCell(table, job.getJobClass().getClass().getName()); writeTableCell(table, "Job State"); writeTableCell(table, job.getJobStateString()); document.add(table); // Write the schedule config if appropriate. if (includeScheduleConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Schedule Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Date startTime = job.getStartTime(); String startStr; if (startTime == null) { startStr = "(Not Available)"; } else { startStr = dateFormat.format(startTime); } writeTableCell(table, "Scheduled Start Time"); writeTableCell(table, startStr); Date stopTime = job.getStopTime(); String stopStr; if (stopTime == null) { stopStr = "(Not Specified)"; } else { stopStr = dateFormat.format(stopTime); } writeTableCell(table, "Scheduled Stop Time"); writeTableCell(table, stopStr); int duration = job.getDuration(); String durationStr; if (duration > 0) { durationStr = duration + " seconds"; } else { durationStr = "(Not Specified)"; } writeTableCell(table, "Scheduled Duration"); writeTableCell(table, durationStr); writeTableCell(table, "Number of Clients"); writeTableCell(table, String.valueOf(job.getNumberOfClients())); String[] requestedClients = job.getRequestedClients(); if ((requestedClients != null) && (requestedClients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < requestedClients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Requested Clients"); table.addCell(clientTable); } String[] monitorClients = job.getResourceMonitorClients(); if ((monitorClients != null) && (monitorClients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < monitorClients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Resource Monitor Clients"); table.addCell(clientTable); } writeTableCell(table, "Threads per Client"); writeTableCell(table, String.valueOf(job.getThreadsPerClient())); writeTableCell(table, "Thread Startup Delay"); writeTableCell(table, job.getThreadStartupDelay() + " milliseconds"); writeTableCell(table, "Statistics Collection Interval"); writeTableCell(table, job.getCollectionInterval() + " seconds"); document.add(table); } // Write the job-specific parameter information if appropriate. if (includeJobConfig) { document.add(new Paragraph(" ")); p = new Paragraph("Parameter Information", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Parameter[] params = job.getParameterList().getParameters(); for (int i = 0; i < params.length; i++) { writeTableCell(table, params[i].getDisplayName()); writeTableCell(table, params[i].getDisplayValue()); } document.add(table); } // Write the statistical data if appropriate. if (includeStats && job.hasStats()) { document.add(new Paragraph(" ")); p = new Paragraph("General Execution Data", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)); document.add(p); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 30, 70 }); Date actualStartTime = job.getActualStartTime(); String startStr; if (actualStartTime == null) { startStr = "(Not Available)"; } else { startStr = dateFormat.format(actualStartTime); } writeTableCell(table, "Actual Start Time"); writeTableCell(table, startStr); Date actualStopTime = job.getActualStopTime(); String stopStr; if (actualStopTime == null) { stopStr = "(Not Available)"; } else { stopStr = dateFormat.format(actualStopTime); } writeTableCell(table, "Actual Stop Time"); writeTableCell(table, stopStr); int actualDuration = job.getActualDuration(); String durationStr; if (actualDuration > 0) { durationStr = actualDuration + " seconds"; } else { durationStr = "(Not Available)"; } writeTableCell(table, "Actual Duration"); writeTableCell(table, durationStr); String[] clients = job.getStatTrackerClientIDs(); if ((clients != null) && (clients.length > 0)) { PdfPTable clientTable = new PdfPTable(1); for (int i = 0; i < clients.length; i++) { PdfPCell clientCell = new PdfPCell(new Phrase(clients[i])); clientCell.setBorder(0); clientTable.addCell(clientCell); } writeTableCell(table, "Clients Used"); table.addCell(clientTable); } document.add(table); String[] trackerNames = job.getStatTrackerNames(); for (int i = 0; i < trackerNames.length; i++) { StatTracker[] trackers = job.getStatTrackers(trackerNames[i]); if ((trackers != null) && (trackers.length > 0)) { document.newPage(); StatTracker tracker = trackers[0].newInstance(); tracker.aggregate(trackers); document.add(new Paragraph(" ")); document.add(new Paragraph(trackerNames[i], FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK))); String[] summaryNames = tracker.getSummaryLabels(); String[] summaryValues = tracker.getSummaryData(); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 50 }); for (int j = 0; j < summaryNames.length; j++) { writeTableCell(table, summaryNames[j]); writeTableCell(table, summaryValues[j]); } document.add(table); if (includeGraphs) { try { ParameterList params = tracker.getGraphParameterStubs(job); BufferedImage graphImage = tracker.createGraph(job, Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_GRAPH_HEIGHT, params); Image image = Image.getInstance(imageToByteArray(graphImage)); image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5)); document.add(image); } catch (Exception e) { } } } } } // Write the resource monitor data if appropriate. if (includeMonitorStats && job.hasResourceStats()) { String[] trackerNames = job.getResourceStatTrackerNames(); for (int i = 0; i < trackerNames.length; i++) { StatTracker[] trackers = job.getResourceStatTrackers(trackerNames[i]); if ((trackers != null) && (trackers.length > 0)) { document.newPage(); StatTracker tracker = trackers[0].newInstance(); tracker.aggregate(trackers); document.add(new Paragraph(" ")); document.add(new Paragraph(trackerNames[i], FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK))); String[] summaryNames = tracker.getSummaryLabels(); String[] summaryValues = tracker.getSummaryData(); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 50 }); for (int j = 0; j < summaryNames.length; j++) { writeTableCell(table, summaryNames[j]); writeTableCell(table, summaryValues[j]); } document.add(table); if (includeGraphs) { try { ParameterList params = tracker.getGraphParameterStubs(job); BufferedImage graphImage = tracker.createMonitorGraph(job, Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_MONITOR_GRAPH_HEIGHT, params); Image image = Image.getInstance(imageToByteArray(graphImage)); image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5)); document.add(image); } catch (Exception e) { } } } } } }