List of usage examples for com.itextpdf.text.html.simpleparser StyleSheet loadStyle
public void loadStyle(String className, String key, String value)
From source file:ilarkesto.integration.itext.Html.java
License:Open Source License
@Override public Element[] createITextElements(Document document) { String cssClassName = "itextpdfelement"; code = "<div class='" + cssClassName + "'>" + code + "</div>"; StyleSheet css = new StyleSheet(); css.loadStyle(cssClassName, "font-family", fontStyle.getFont()); css.loadStyle(cssClassName, "color", fontStyle.getColor().toString()); css.loadStyle(cssClassName, "font-size", APdfBuilder.mmToPoints(fontStyle.getSize()) + "pt"); css.loadStyle(cssClassName, "size", APdfBuilder.mmToPoints(fontStyle.getSize()) + "pt"); css.loadStyle(cssClassName, "line-height", "100em"); StringReader reader = new StringReader(code); List<Element> elements; HTMLWorker worker = new HTMLWorker(document); try {/*from w ww.j a v a2s .c om*/ elements = worker.parseToList(reader, css); } catch (IOException ex) { throw new RuntimeException(ex); } return Utl.toArray(elements, new Element[elements.size()]); }
From source file:net.apocalypselabs.symat.CodeExport.java
License:Open Source License
private void savePdfFile(String html, String path) { try {/*from w w w .j av a2s. c o m*/ String k = html; try (OutputStream file = new FileOutputStream(new File(path))) { Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); HTMLWorker htmlWorker = new HTMLWorker(document); StyleSheet styles = new StyleSheet(); styles.loadStyle("com", "color", "green"); styles.loadStyle("kwd", "color", "blue"); styles.loadStyle("pln", "color", "black"); styles.loadStyle("lit", "color", "#0099cc"); styles.loadStyle("pun", "color", "black"); styles.loadStyle("pun", "font-weight", "bold"); htmlWorker.setStyleSheet(styles); htmlWorker.parse(new StringReader(k)); document.close(); savedMsg(); } } catch (IOException | DocumentException e) { JOptionPane.showInternalMessageDialog(this, "Error saving: " + e.getMessage()); } }