2012-09-21 46 views
0

我有用戶在富文本框(rtb)中輸入一些文本的WPF應用程序,我將該rtb字符串轉換爲HTML,然後將該HTML轉換爲圖像,然後將其插入PDF文檔使用itextsharp直接在PDF中插入HTML

using (Stream inputPdfStream = new FileStream("sample.pdf", FileMode.Open, FileAccess.Read, FileShare.Read)) 
using (Stream outputPdfStream = new FileStream("result2.pdf", FileMode.Create, FileAccess.Write, FileShare.None)) 
{ 
    var reader = new PdfReader(inputPdfStream); 
    var stamper = new PdfStamper(reader, outputPdfStream); 

    PdfContentByte pdfContentByte = null; 

    int c = reader.NumberOfPages; 
    iTextSharp.text.Image image = TextSharp.text.Image.GetInstance(ConvertXamltohtmltoImage(xamlstring)); 

    foreach (var item in lst) 
    { 
     image.ScaleToFit(item._Size.Width, item._Size.Height); 
     image.SetAbsolutePosition(item.Location.X, item.Location.Y); 
     pdfContentByte = stamper.GetOverContent(item.pageNo); 
     pdfContentByte.AddImage(image); 
    } 
    stamper.Close(); 
} 

我的問題是我可以直接插入HTML到PDF?

回答

1

你需要一個額外的DLL來做到這一點:http://sourceforge.net/projects/itextsharp/files/xmlworker/ 觀看演示:http://demo.itextsupport.com/xmlworker/ 不幸的是,該文件並沒有被最近更新。我們正在努力。

+0

iTextSharp對html的支持相當差。你可能無法處理所有的html標籤 –

+0

它有相同的許可證適用於itextsharp,因爲我使用的版本是4.1.6? – Haider

+1

不,請閱讀http://lowagie.com/iText2和http://lowagie.com/FOSSHygiene以及http://lowagie.com/bumodels –