简体   繁体   中英

iTextSharp support for HTML controls conversion C#

Does iTextSharp HTML to PDF conversion support controls like Textboxes, Buttons etc.? Or we need to use iTextSharp class like TextField to implement controls during PDF conversion.

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. 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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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