使用itextsharp直接在PDF中插入HTML [英] Insert HTML directly in PDF using itextsharp
问题描述
我有WPF应用程序,用户在富文本框(rtb)中输入一些文本,我将该rtb字符串转换为HTML,然后将该HTML转换为图像,然后将其插入PDF文档
I have WPF application in which user enters some text in rich text box(rtb), I convert that rtb string to HTML and then convert that HTML to image and then insert it in the PDF document
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吗?
My question is can I insert HTML directly into PDF?
推荐答案
你需要一个额外的DLL才能做到这一点: http://sourceforge.net/projects/itextsharp/files/xmlworker/
请参阅演示: http://demo.itextsupport.com/xmlworker/
不幸的是,该文档最近没有更新。我们正在努力。
You need an extra DLL to do that: http://sourceforge.net/projects/itextsharp/files/xmlworker/ See the demo: http://demo.itextsupport.com/xmlworker/ Unfortunately, the documentation hasn't been updated recently. We're working on it.
这篇关于使用itextsharp直接在PDF中插入HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!