Converting HTML to PDF with pdfHTML

https://itextpdf.com/itext7/pdfHTMLcss

pdfHTML 的一個例子

一個基本的例子將顯示使用 pdfHTML。爲此, 咱們將使用下面的 HTML 和 CSS。

 

        <head> <style> p { color : #084975; } div{ color: #F99D25; } </style> </head> <body> <p>iText</p> <div>Your developer journey with iText begins here</div> </body>

輸出將使用如下代碼直接寫入 PDF 文件:html

 

    public static void main() throws IOException {
 
        // IO
        File htmlSource = new File("input.html");
        File pdfDest = new File("output.pdf");
 
        // pdfHTML specific code
        ConverterProperties converterProperties = new ConverterProperties();
        HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), converterProperties);
    }
相關文章
相關標籤/搜索