简体   繁体   English

iTextSharp 支持 HTML 控件转换 C#

[英]iTextSharp support for HTML controls conversion C#

Does iTextSharp HTML to PDF conversion support controls like Textboxes, Buttons etc.? iTextSharp HTML 到 PDF 转换是否支持文本框、按钮等控件? Or we need to use iTextSharp class like TextField to implement controls during PDF conversion.或者我们需要使用像TextField这样的iTextSharp类来实现PDF转换过程中的控件。

iTextSharp doesn't support convertion of text boxes, buttons, etc. Most likely, you need to implement your own logic if you want to covert the html page (with text boxes, buttons, etc.) to a pdf document. iTextSharp 不支持文本框、按钮等的转换。如果要将 html 页面(带有文本框、按钮等)转换为 pdf 文档,很可能需要实现自己的逻辑。 You can find all supported tags and styles here .您可以在此处找到所有支持的标签和样式。 You can also check whether an element is supported using this simple example:您还可以使用以下简单示例检查元素是否受支持:

byte[] bytes;
using (var stream = new MemoryStream())
{
     using (var document = new Document())
     {
          using (var writer = PdfWriter.GetInstance(document, stream))
          {
               document.Open();
               var html = @"<p>Before the button</p><br/><input type=""submit"" value=""Click me""/><br/><p>After the button</p>";
               using (var reader = new StringReader(html))
               {
                    XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, reader);
               }                   
               document.Close();
          }
     }
     bytes = stream.ToArray();
}
File.WriteAllBytes("test.pdf", bytes);

If you run this example, you'll see that the input element is not a part of the final document:如果你运行这个例子,你会看到input元素不是最终文档的一部分:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM