How to Convert XML to PDF in C# and VB.Net ?

XML may be rendered to PDF via HTML(5) using XLST transformations. These documents define how XML from a given schema may be converted to an accurate HTML representation and are a well established standard.

https://docs.microsoft.com/en-us/dotnet/standard/data/xml/using-the-xslcompiledtransform-class

The resultant HTML string or file may then be rendered as a PDF using IronPDF:


    XslCompiledTransform transform = new XslCompiledTransform();

    using(XmlReader reader = XmlReader.Create(new StringReader(XSLT))) {

        transform.Load(reader);

    }

    StringWriter results = new StringWriter();

    using(XmlReader reader = XmlReader.Create(new StringReader(XML))) {

        transform.Transform(reader, null, results);

    }

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();

// options, headers and footers may be set there

// Render our XML as a PDF via XSLT

Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
Dim transform As XslCompiledTransform = New XslCompiledTransform
Imports (
Dim reader As XmlReader = XmlReader.Create(New StringReader(XSLT))
UnknownDim results As StringWriter = New StringWriter
Imports (
Dim reader As XmlReader = XmlReader.Create(New StringReader(XML))
,Nothing
,results
UnknownUnknownDim Renderer As IronPdf.HtmlToPdf = New IronPdf.HtmlToPdf
' options, headers and footers may be set there
' Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString).SaveAs("Final.pdf")
VB   C#