Example usage for com.itextpdf.text.html.simpleparser HTMLWorker setStyleSheet

List of usage examples for com.itextpdf.text.html.simpleparser HTMLWorker setStyleSheet

Introduction

In this page you can find the example usage for com.itextpdf.text.html.simpleparser HTMLWorker setStyleSheet.

Prototype

public void setStyleSheet(StyleSheet style) 

Source Link

Document

Setter for the StyleSheet

Usage

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());
    }
}