您可以使用iText
和XMLWorker
從HTML代碼創建PDF。
public void createPDF() throws DocumentException, IOException
{
String fileName="path you want to create the document";
Document document=new Document();
PdfWriter pdfWriter=PdfWriter.getInstance(document, new FileOutputStream(fileName));
document.open();
String finall="<h1>This is a Demo</h1>";
InputStream is = new ByteArrayInputStream(finall.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter,document, is);
document.close();
}
在這裏,我們使用XML工作,所以你所有的標籤應該正確關閉。您需要iText
和XMLWorker
JAR文件。希望這會對您有所幫助。
你能舉個例子嗎?並鏈接到那些jar文件請 – user176105
也itext是非常昂貴的。有沒有更便宜的選擇,一樣好? – user176105
如果我的答案可以幫助您接受它,可以從以下鏈接下載XMLWorker http://sourceforge.net/projects/xmlworker/files/ –