Best way to create PDF from XML XSLT in C#
In the past I've used a commercial library called Ibex PDF Creator to generate PDF documents from XML data using the XSL-FO standard that has worked really well.
Here's an example of how I would use it:
XML data:
<DocumentRoot>
<!-- Some content -->
</DocumentRoot>
XSL-FO layout:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/DocumentRoot">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ibex="http://www.xmlpdf.com/2003/ibex/Format">
<ibex:properties
title="Some document"
subject=""
author=""
keywords=""
creator="" />
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm">
<fo:region-body margin-bottom="1cm" margin-top="3cm"/>
<fo:region-before extent="20mm"/>
<fo:region-after extent="8mm"/>
<fo:region-start extent="1mm"/>
<fo:region-end extent="1mm"/>
</fo:simple-page-master>
</fo:layout-master-set>
</<fo:root>
</xsl:template>
</xsl:stylesheet>
Generating the PDF document in .NET:
var data = new MemoryStream(dataBytes);
var layout = new MemoryStream(layoutBytes);
var pdf = new MemoryStream();
// Using the Ibex PDF Creator .NET API
var doc = new FODocument();
doc.generate(data, layout, pdf);
I hope this helps.