Java 类com.lowagie.text.html.simpleparser.HTMLWorker 实例源码

项目:document-management-system    文件:DocConverter.java   
/**
 * Convert HTML to PDF
 */
public void html2pdf(File input, File output) throws ConversionException, DatabaseException, IOException {
    log.debug("** Convert from HTML to PDF **");
    FileOutputStream fos = null;

    try {
        fos = new FileOutputStream(output);

        // Make conversion
        Document doc = new Document(PageSize.A4);
        PdfWriter.getInstance(doc, fos);
        doc.open();
        HTMLWorker html = new HTMLWorker(doc);
        html.parse(new FileReader(input));
        doc.close();
    } catch (DocumentException e) {
        throw new ConversionException("Exception in conversion: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}
项目:document-management-system    文件:DocConverter.java   
/**
 * Convert SRC to PDF
 */
public void src2pdf(File input, File output, String lang) throws ConversionException, DatabaseException, IOException {
    log.debug("** Convert from SRC to PDF **");
    FileOutputStream fos = null;
    FileInputStream fis = null;

    try {
        fos = new FileOutputStream(output);
        fis = new FileInputStream(input);

        // Make syntax highlight
        String source = IOUtils.toString(fis);
        JaSHi jashi = new JaSHi(source, lang);
        // jashi.EnableLineNumbers(1);
        String parsed = jashi.ParseCode();

        // Make conversion to PDF
        Document doc = new Document(PageSize.A4.rotate());
        PdfWriter.getInstance(doc, fos);
        doc.open();
        HTMLWorker html = new HTMLWorker(doc);
        html.parse(new StringReader(parsed));
        doc.close();
    } catch (DocumentException e) {
        throw new ConversionException("Exception in conversion: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}