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?
iTextSharp對html的支持相當差。你可能無法處理所有的html標籤 –
它有相同的許可證適用於itextsharp,因爲我使用的版本是4.1.6? – Haider
不,請閱讀http://lowagie.com/iText2和http://lowagie.com/FOSSHygiene以及http://lowagie.com/bumodels –