List of usage examples for com.lowagie.text Element toString
public String toString();
From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java
License:Open Source License
/** * Flushes the stack, adding all objects in it to the document. *//* w ww . j a v a 2s. co m*/ private void flushStack() { //printlnerr("entering flushStack; stack: " + stackStatus()); Stack<Element> reverseStack = new Stack<Element>(); try { //printlnerr("*** FLUSH COMMENCE ***"); //debugElementStack(stack); while (stack.size() > 0) { Element element = null; try { element = (Element) popFromStack(); if (!(element instanceof TextElementArray)) { System.err.print(""); printlnerr("Orphaned element: [" + element.toString() + "]"); } else if (element instanceof Anchor) { reverseStack.push(element); } else { TextElementArray previous = (TextElementArray) popFromStack(); if (previous != null) { if (previous instanceof Anchor) { reverseStack.push(element); reverseStack.push(previous); } else { previous = appendToTEA(previous, element); pushToStack(previous); } } else { pushToStack(element); } } } catch (EmptyStackException es) { if (element != null) { reverseStack.push(element); } } } //printlnerr("*** FLUSH ***"); } catch (Exception e) { e.printStackTrace(); printerr(""); } //printlnerr("*** ADDING TO PDF ***"); //debugElementStack(reverseStack); try { printerr(""); while (reverseStack.size() > 0) { Element elemToAdd = reverseStack.pop(); if (elemToAdd instanceof TextElementArray) { checkTextElementArrayForTocAnchors(document, (TextElementArray) elemToAdd); } addToDocument(elemToAdd); } } catch (DocumentException docEx) { docEx.printStackTrace(); } }
From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java
License:Open Source License
static String getAbridgedContents(Element elem) { String content = ""; if (elem != null) content += elem.toString(); int len = content.length(); if (len > 25) { StringBuilder sB = new StringBuilder(); sB.append(content.substring(0, 10)); sB.append(" ... "); sB.append(content.substring(len - 10)); content = sB.toString();// w ww .j a v a 2 s . c o m } if (elem instanceof Anchor) { Anchor elemAnchor = (Anchor) elem; StringBuilder sB = new StringBuilder(); sB.append('_'); sB.append(elemAnchor.getName()); if (elemAnchor.getReference() != null) { sB.append("->"); sB.append(elemAnchor.getReference()); } sB.append(":"); sB.append(content); content = sB.toString(); } return content; }
From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java
License:Educational Community License
public void addElementWithJump(Element currentPara, boolean jumpIfLittleSpace) { //20140226 - daniel.merino@unavarra.es - https://jira.sakaiproject.org/browse/EVALSYS-1100 //Adds a big size element (a header or a graphic) and jumps to another page/column if it detects that is below the last third of the document. float y = responseArea.getYLine(); LOG.debug("Vertical position Y: " + y); try {/*from w w w. j a va 2 s . com*/ if ((jumpIfLittleSpace) && (y < (document.top() / 3))) { //If there's little space to the bottom border, we jump to the next column. I use this only for headers. column = Math.abs(column - 1); if (column == 0) { document.newPage(); responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2, document.bottom() + pagefooter); } else { responseArea.setSimpleColumn(document.right() / 2, document.top(), document.right(), document.bottom() + pagefooter); } //Just to align vertically the top elements if (!currentPara.toString().equals("[ ]")) responseArea.addElement(new Paragraph(" ")); } responseArea.addElement(currentPara); responseArea.go(); } catch (DocumentException e) { // TODO Auto-generated catch block throw UniversalRuntimeException.accumulate(e, "Unable to add element to PDF Report"); } }