List of usage examples for com.itextpdf.text.html.simpleparser HTMLWorker setStyleSheet
public void setStyleSheet(StyleSheet style)
From source file:net.apocalypselabs.symat.CodeExport.java
License:Open Source License
private void savePdfFile(String html, String path) { try {/* w w w . j a v a 2 s. co 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()); } }