List of usage examples for com.itextpdf.text.html.simpleparser HTMLWorker parseToList
public static List<Element> parseToList(final Reader reader, final StyleSheet style, final HashMap<String, Object> providers) throws IOException
From source file:net.sf.texprinter.generators.PDFGenerator.java
License:Open Source License
/** * Parses the HTML text to a list of elements. * /*from w ww. java2 s . c o m*/ * @param text The text. * @return A list of elements. * @throws IOException Throws an IOException if the StringReader couldn't * get the string provided. */ private static List<Element> getPostText(String text) throws IOException { // set the text to a snippet String snippet = text; // full code tag is not supported snippet = snippet.replaceAll("<pre><code>", "<pre>"); snippet = snippet.replaceAll("<pre class=.*\"><code>", "<pre>"); snippet = snippet.replaceAll("</code></pre>", "</pre>"); // code tag is not supported snippet = snippet.replaceAll("<code>", "<font face=\"Courier\">"); snippet = snippet.replaceAll("</code>", "</font>"); // add new lines snippet = snippet.replaceAll("\n", "<br/>"); // create a new stylesheet StyleSheet styles = new StyleSheet(); // configure lists styles.loadTagStyle("ul", "indent", "10"); styles.loadTagStyle("li", "leading", "14"); // configure hyperlinks styles.loadTagStyle("a", "color", "blue"); // create a map of providers HashMap providers = new HashMap(); // set the image provider providers.put("img_provider", new TeXImageFactory()); // parse the HTML to a list List<Element> objects = HTMLWorker.parseToList(new StringReader(snippet), styles, providers); // return the new list return objects; }