Convert XML to PDF Using XSLT and IronPDF
XML cannot render to PDF directly, so the path runs in two steps: an XSLT stylesheet transforms the XML into HTML, then IronPDF renders that HTML to PDF through its Chrome engine. IronPDF owns only the final leg; XSLT does the shaping. That split keeps data (the XML) and presentation (the stylesheet) apart, and the use cases below all lean on it.
using IronPdf;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
var transform = new XslCompiledTransform();
transform.Load("invoice.xslt");
using var writer = new StringWriter();
using (var reader = XmlReader.Create("invoice.xml"))
{
transform.Transform(reader, null, writer);
}
new ChromePdfRenderer()
.RenderHtmlAsPdf(writer.ToString())
.SaveAs("invoice.pdf");
using IronPdf;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
var transform = new XslCompiledTransform();
transform.Load("invoice.xslt");
using var writer = new StringWriter();
using (var reader = XmlReader.Create("invoice.xml"))
{
transform.Transform(reader, null, writer);
}
new ChromePdfRenderer()
.RenderHtmlAsPdf(writer.ToString())
.SaveAs("invoice.pdf");
Imports IronPdf
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Dim transform As New XslCompiledTransform()
transform.Load("invoice.xslt")
Using writer As New StringWriter()
Using reader As XmlReader = XmlReader.Create("invoice.xml")
transform.Transform(reader, Nothing, writer)
End Using
Dim renderer As New ChromePdfRenderer()
renderer.RenderHtmlAsPdf(writer.ToString()).SaveAs("invoice.pdf")
End Using
(Note: Transform writes into the StringWriter; it does not return the HTML, so you read writer.ToString() after the call.)
E-invoicing and machine-readable invoice formats
Here the pipeline pays off most. Standards like UBL, Factur-X, and ZUGFeRD carry invoices as XML data, not as documents anyone can read. A stylesheet turns that XML into a formatted invoice, and IronPDF produces the PDF a person actually receives.
Regulated data feeds in finance, government, and healthcare
These industries exchange structured XML: tax filings, financial statements, clinical documents, regulatory submissions. Each schema maps to a compliant printed layout through its own stylesheet, with the transformation logic kept out of your C#.
Product catalogs and price lists
A catalog feed in XML becomes a formatted brochure or table through a stylesheet, with styling handled by familiar HTML and CSS rather than a proprietary PDF language.
One source, many document variants
Because presentation lives in the template, one XML source can produce several outputs (customer invoice, internal copy, localized version) by swapping stylesheets. No data changes, no recompiling.
Parameterized and conditional documents
Pass runtime values into the transform with XsltArgumentList, so one template can branch on currency, region, or draft status before rendering:
var args = new XsltArgumentList();
args.AddParam("currency", "", "AUD");
using var writer = new StringWriter();
using (var reader = XmlReader.Create("invoice.xml"))
{
transform.Transform(reader, args, writer);
}
var args = new XsltArgumentList();
args.AddParam("currency", "", "AUD");
using var writer = new StringWriter();
using (var reader = XmlReader.Create("invoice.xml"))
{
transform.Transform(reader, args, writer);
}
Imports System.Xml
Imports System.Xml.Xsl
Imports System.IO
Dim args As New XsltArgumentList()
args.AddParam("currency", "", "AUD")
Using writer As New StringWriter()
Using reader As XmlReader = XmlReader.Create("invoice.xml")
transform.Transform(reader, args, writer)
End Using
End Using
When not to use this
For a simple XML structure or a one-off conversion, the XSLT layer is overhead; parse the XML and build the HTML directly. The stylesheet approach proves its worth in systems handling varied schemas or needing maintainable, reusable transformation logic.
Why the split is the point
The pipeline's strength is that separation. IronPDF gives you pixel-accurate rendering on the last step, but the flexibility, multiple formats, conditional layouts, schema independence, all comes from keeping the transform in XSLT rather than in code.
Frequently Asked Questions
Can IronPDF convert XML directly to PDF?
Not directly. The pipeline runs in two steps: an XSLT stylesheet transforms the XML into HTML, then IronPDF renders that HTML to PDF through its Chrome engine. IronPDF handles only the final rendering step.
How do I convert XML to PDF in C# using XSLT and IronPDF?
Load the XSLT file with XslCompiledTransform, transform the XML into an HTML string using a StringWriter, then pass that string to ChromePdfRenderer.RenderHtmlAsPdf. Note that Transform writes to the writer — call writer.ToString() to get the HTML after the transform completes.
What are the advantages of using XSLT to transform XML before rendering to PDF?
Keeping data (XML) and presentation (XSLT stylesheet) separate means one XML source can produce multiple document variants (customer invoice, internal copy, localized version) by swapping stylesheets. Transformation logic stays out of C# code and remains reusable across schemas.
Can I pass parameters into the XSLT transform at runtime?
Yes. Use XsltArgumentList with AddParam to pass values like currency, region, or draft status into the stylesheet before rendering. The template can then branch on those values to produce conditional output.
What e-invoicing standards can this pipeline handle?
The XSLT pipeline can handle any XML-based invoice standard including UBL (Universal Business Language), Factur-X, and ZUGFeRD. These carry invoice data as structured XML; a corresponding XSLT stylesheet transforms each format into a human-readable HTML layout, which IronPDF renders to PDF.

