PdfSourceType Enumeration |
Namespace: MailBee.Pdf
Member name | Value | Description | |
---|---|---|---|
Html | 0 | Use HTML as input data source. HtmlAgilityPack will be used to make the input XHTML-compliant XML. | |
Xhtml | 1 | Use XHTML wrapped in XML (XMLized XHTML) as input data source. HtmlAgilityPack won't be used as the input is already expected to be XML-compliant XHTML. | |
Text | 2 | Use plain text as input data source. Will wrap plain-text into XMLized XHTML as shown in the second example above. |
Internally, the component always takes XML on input in order to produce PDF content. This XML is much like XHTML with <xml> element and some restrictions like the necessity to encode styles and javascript in CDATA blocks. MailBee automatically does all the required conversion of any HTML into this XHTML-over-XML format. However, your application can provide this XHTML-over-XML on input to avoid such conversion in MailBee. In this case, use Xhtml value for SourceType property.
This can be useful in case if you want to use OnConvertXmlNodeToPdf delegate to precisely control how some nodes of the input data are converted from XML to PDF. In this case, providing HTML input may not be sufficient as you may not know which nodes will exist in the document after HTML-to-XML conversion. Providing the input which can be consumed by the PDF producer without any additional conversion of HTML into XML solves this problem - OnConvertXmlNodeToPdf delegate will fire on the same nodes your document contains.
Note |
---|
PDF functionality resides in a separate MailBee.NET.PDF.dll. It's available for .NET Framework only (not available for .NET Core or UWP). It also depends on iTextSharp.dllHtmlAgilityPack.dll. In case of Nuget, you need to install a separate MailBee.NET.PDF package (includes all the required DLLs). |
HtmlDocument html = new HtmlDocument(); html.OptionSupportOptionalEndTags = true; html.LoadHtml(source); html.OptionOutputAsXml = true; StringWriter sw = new StringWriter(); html.Save(sw); xml = sw.ToString();
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><span><html><body><pre>"); sb.Append(HttpUtility.HtmlEncode(source)); sb.Append("</pre></body></html></span>"); xml = sb.ToString();