List of usage examples for com.itextpdf.text.html.simpleparser StyleSheet loadTagStyle
public void loadTagStyle(String tag, String key, String value)
From source file:com.framework.example.html2pdf.ConvertDemo.java
public static void htmlCodeComeFromFile(String filePath, String pdfPath) { Document document = new Document(); try {//w ww .j av a2 s .co m StyleSheet st = new StyleSheet(); st.loadTagStyle("body", "leading", "16,0"); PdfWriter.getInstance(document, new FileOutputStream(pdfPath)); document.open(); ArrayList p = (ArrayList) HTMLWorker.parseToList(new FileReader(filePath), st); for (int k = 0; k < p.size(); ++k) { document.add((Element) p.get(k)); } document.close(); System.out.println("?"); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.unisiegen.informatik.bs.alvis.export.PdfExport.java
License:Open Source License
/** * adds organized, structured, highlighted source code to new paragraph and * returns it/*from w w w. j a v a2s. c o m*/ * * @author Sebastian Schmitz & Frank Weiler * @param sourceCode * the source code as string including html tags for highlighting * etc * @return a paragraph including the source code * @throws DocumentException * will be thrown when new paragraph could not have been added */ private Paragraph toParagraph(StyledText sourceCode) throws DocumentException { if (sourceCode == null) return null; String content = highlightStyleTextinHTML(sourceCode); // returnt den // nicht // eingerckten, // aber // gehighlighteten // Code Paragraph paragraph = new Paragraph(); if (content != null) { content = indentCode(content); // rckt den Code ein List<Element> bodyText; StyleSheet styles = new StyleSheet(); styles.loadTagStyle("ol", "leading", "16,0"); try { bodyText = HTMLWorker.parseToList(new StringReader(content), styles); paragraph.setFont(FontFactory.getFont("Courier", 10, Font.NORMAL)); for (Element elem : bodyText) { paragraph.add(elem); } } catch (IOException e) { paragraph.add(Messages.noSourceCodeAdded); } } return paragraph; }
From source file:de.unisiegen.informatik.bs.alvis.export.PdfExport.java
License:Open Source License
/** * adds one line of organized, structured, highlighted source code to new * paragraph and returns it/* w w w . j ava2 s.co m*/ * * @author Sebastian Schmitz & Frank Weiler * @param sourceCode * the source code as string including html tags for highlighting * etc * @param wantedLineIndex * the wanted line number * @return a paragraph including the source code line * @throws DocumentException * will be thrown when new paragraph could not have been added */ private Paragraph toParagraph(StyledText sourceCode, int wantedLineIndex) throws DocumentException { if (sourceCode == null) return null; if (wantedLineIndex < 0 || wantedLineIndex >= sourceCode.getLineCount()) return null; String content = highlightStyleTextinHTML(sourceCode, wantedLineIndex); Paragraph paragraph = new Paragraph(); if (content != null) { List<Element> bodyText; StyleSheet styles = new StyleSheet(); styles.loadTagStyle("ol", "leading", "16,0"); try { bodyText = HTMLWorker.parseToList(new StringReader(content), styles); paragraph.setFont(FontFactory.getFont("Courier", 10, Font.NORMAL)); for (Element elem : bodyText) { paragraph.add(elem); } } catch (IOException e) { paragraph.add(Messages.noSourceCodeAdded); } } return paragraph; }
From source file:net.sf.texprinter.generators.PDFGenerator.java
License:Open Source License
/** * Parses the HTML text to a list of elements. * // ww w . j av a 2s. 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; }