List of usage examples for com.lowagie.text Font UNDERLINE
int UNDERLINE
To view the source code for com.lowagie.text Font UNDERLINE.
Click Source Link
From source file:test.itext.html.AimsPdf.java
License:Open Source License
private static void writeData(Document doc, StringBuffer sb, String headingText) throws IOException, DocumentException { String data = Utility.replace(sb.toString(), "<p> </p>", "", Utility.REPLACE_ALL); data = Utility.replace(data, "</p>", "</p><br/>", Utility.REPLACE_ALL); data = Utility.replace(data, "</ul>", "</ul><br/>", Utility.REPLACE_ALL); data = Utility.replace(data, "</p><br/></td>", "</p></td>", Utility.REPLACE_ALL); System.out.println(data);//from w w w.ja v a 2 s .c om Reader reader = new StringReader("<root>" + data + "</root>"); if (headingText != null && headingText.length() > 0) { Paragraph heading = new Paragraph(headingText, FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC)); heading.setSpacingAfter(12f); doc.add(heading); } ArrayList objects = HTMLWorker.parseToList(reader, style, null); for (int k = 0; k < objects.size(); ++k) { Element ele = (Element) objects.get(k); doc.add(ele); } reader.close(); }
From source file:textdisplay.TagFilter.java
License:Educational Community License
public void replaceTagsWithPDFEncoding(String[] tags, styles[] tagStyles, OutputStream os) throws DocumentException { // FileWriter w = null; try {//from www . ja va 2 s .c om BaseFont bf = BaseFont.createFont("/usr/Junicode.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Document doc = new Document(); PdfWriter p = PdfWriter.getInstance(doc, os); doc.open(); Paragraph para = new Paragraph(); para.setFont(new Font(bf, 12, Font.NORMAL)); //doc.add(para); Font italic = new Font(bf, 12, Font.ITALIC); Font bold = new Font(bf, 12, Font.BOLD); Font underlined = new Font(bf, 12, Font.UNDERLINE); StringBuilder chunkBuffer = new StringBuilder(""); //holds the next bit of content that will be added to the pdf as a chunk styles chunkStyle = null; //the style to be applied to chunkBuffer when it gets added to the document String chunkTag = ""; Stack<String> wrappingTags = new Stack(); Stack<styles> wrappingStyles = new Stack(); String content = text; Boolean inTag = false; //is this inside a tag, meaning between the < and > String tagTextBuffer = ""; //the text of the tag, including name and any parameters Boolean beingTagged = false; //Is the parser currently reading character data that is surrounded by a tag that demands styling for (int charCounter = 0; charCounter < this.text.length(); charCounter++) { if (text.charAt(charCounter) == '>') { inTag = false; //if this was a self closing tag, dont do anything if (tagTextBuffer.contains("/>")) { tagTextBuffer = ""; } else { //this is a closing tag, save the chunk and pop the tag and style off of the stack if (tagTextBuffer.startsWith("/")) { if (chunkStyle != null) System.out.print(" closing tag " + tagTextBuffer + " with style " + chunkStyle.name() + "\n"); else System.out.print(" closing tag " + tagTextBuffer + " with style null" + "\n"); if (chunkStyle == styles.paragraph) chunkBuffer = new StringBuilder("\n" + chunkBuffer); Chunk c = new Chunk(chunkBuffer.toString()); styleChunk(c, chunkStyle); if (chunkStyle != styles.remove) para.add(c); chunkBuffer = new StringBuilder(""); chunkStyle = null; chunkTag = ""; if (!wrappingStyles.empty()) { chunkStyle = wrappingStyles.pop(); chunkTag = wrappingTags.pop(); } tagTextBuffer = ""; } else { //this is the closing bracket of an opening tag String tagName = tagTextBuffer.split(" ")[0]; System.out.print("tag is " + tagName + "\n"); for (int i = 0; i < tags.length; i++) { if (tags[i].compareTo(tagName) == 0) { // this is a tag that is suposed to be styled in the pdf if (chunkStyle != null) { //this tag is nested in a tag that was already applying styling. Add this chunk to the pdf and put the tag/style //for the previous tag on the stack, so when this new tag ends, the previous styling will resume. if (chunkStyle == styles.paragraph) chunkBuffer = new StringBuilder("\n" + chunkBuffer); Chunk c = new Chunk(chunkBuffer.toString()); styleChunk(c, chunkStyle); if (chunkStyle != styles.remove) para.add(c); wrappingStyles.add(chunkStyle); wrappingTags.add(chunkTag); chunkTag = tagName; chunkStyle = tagStyles[i]; chunkBuffer = new StringBuilder(""); } else { Chunk c = new Chunk(chunkBuffer.toString()); para.add(c); chunkTag = tagName; chunkStyle = tagStyles[i]; chunkBuffer = new StringBuilder(""); } } } tagTextBuffer = ""; } } } if (inTag) { tagTextBuffer += text.charAt(charCounter); } if (text.charAt(charCounter) == '<') { if (inTag) { //if we hit another < before hitting a > this was not a tag, so add the tagTextBuffer to the chunk. It was simply conent. chunkBuffer.append(tagTextBuffer); tagTextBuffer = ""; } inTag = true; } if (!inTag && text.charAt(charCounter) != '>') { chunkBuffer.append(text.charAt(charCounter)); } } Chunk c = new Chunk(chunkBuffer.toString()); para.add(c); doc.newPage(); doc.add(para); doc.newPage(); doc.close(); } catch (IOException ex) { Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex); } finally { } }
From source file:textdisplay.TagFilter.java
License:Educational Community License
/**Apply a style (font) to a chunk of pdf text*/ private void styleChunk(Chunk c, styles s) { try {/*from ww w. j av a 2 s . c o m*/ BaseFont bf = BaseFont.createFont("/usr/Junicode.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont ita = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont bol = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); if (bf.charExists(540)) { System.out.print("font cant do 540\n"); } Font italic = new Font(ita, 12, Font.ITALIC); Font bold = new Font(bol, 12, Font.BOLD); Font underlined = new Font(bf, 12, Font.UNDERLINE); Font superscript = new Font(bf, 9, Font.NORMAL); if (s == styles.bold) { c.setFont(bold); } if (s == styles.italic) { c.setFont(italic); } if (s == styles.underlined) { c.setFont(underlined); } if (s == styles.superscript) { c.setTextRise(7.0f); c.setFont(superscript); } //wipe out that content } catch (DocumentException ex) { Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex); } }