Insert HTML directly in PDF using itextsharp

a 夏天 提交于 2020-01-06 06:52:46

问题


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();
}

My question is can I insert HTML directly into PDF?


回答1:


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.



来源:https://stackoverflow.com/questions/12529244/insert-html-directly-in-pdf-using-itextsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!