Search code examples
c#.netpdfxsl-fo

Convert xsl - fo to pdf


I have an XSL-FO file and data is available in xml/json formats. I wanted to create a pdf using this xsl structure.

Can anyone suggest any open source libraries for conversion? I want it to be done at the C# level.

Note: I tried converting to html but as it is xsl-fo file I can't get the alignment.


Solution

  • I tried using fo.net and it worked for me, here is the sample code

                string lBaseDir = System.IO.Path.GetDirectoryName("e:\thermalpdf.xsl");
                XslCompiledTransform lXslt = new XslCompiledTransform();
                lXslt.Load("e:\thermalpdf.xsl");
                lXslt.Transform("e:\billingData1.xml", "books1.fo");
                FileStream lFileInputStreamFo = new FileStream("books1.fo", FileMode.Open);
                FileStream lFileOutputStreamPDF = new FileStream("e:\response2.pdf", FileMode.Create);
                FonetDriver lDriver = FonetDriver.Make();
                lDriver.BaseDirectory = new DirectoryInfo(lBaseDir);
                lDriver.CloseOnExit = true;
                lDriver.Render(lFileInputStreamFo, lFileOutputStreamPDF);
                lFileInputStreamFo.Close();
                lFileOutputStreamPDF.Close();