2013-12-21 73 views
1

我在我的網站上有ckeditor(http://ckeditor.com/)。我希望用戶能夠按下按鈕來生成PDF。目前,我讓他們按ckeditor附帶的打印功能,打開打印窗口,並從大多數瀏覽器中生成PDF。但我想簡化一下。我知道從html生成PDF很困難,但是有沒有簡單的解決方案來執行此操作(從ckeditor提供的html生成PDF)?將CKEDITOR轉成pdf

我聽說過一些解決方案,如fpdf,dompdf和html2pdf。

回答

2

您可以使用iTextXMLWorker從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工作,所以你所有的標籤應該正確關閉。您需要iTextXMLWorker JAR文件。希望這會對您有所幫助。

+0

你能舉個例子嗎?並鏈接到那些jar文件請 – user176105

+0

也itext是非常昂貴的。有沒有更便宜的選擇,一樣好? – user176105

+0

如果我的答案可以幫助您接受它,可以從以下鏈接下載XMLWorker http://sourceforge.net/projects/xmlworker/files/ –