We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Create PDF form XLSFO and XML file

Do you have any code exampels (.NET) on how to create a PDF file based on a XSLFO file and an XML file ?


Thanks for contacting support.

Please use following code snippet to convert XSLFO file into PDF:

Document doc = new Aspose.Pdf.Document(dataDir + "input.fo", new XslFoLoadOptions());
doc.Save(dataDir + "output.pdf", SaveFormat.Pdf);

In order to convert XML file into PDF, please visit following article(s) in our API documentation:

This was not what i meant. I have an xml file with data and a xslfo file, i need to combine these two into a pdf file.


Thanks for getting back to us.

Aspose.PDF offers BindXml() method to create PDF using XML and XSLT style. Following code snippet can be used to generate PDF using both files provided that the XML and XSLT elements sequence is based on Aspose.Pdf XML Schema:

Document pdfDocument = new Document();
pdfDocument.BindXml("input.xml", "input.xsl");

In case your sample files are different, please share them with us. We will test the scenario in our environment and address it accordingly.


this is working for me - thanx.

But there is one issue remaning. In the xlst files dimension are set in px:

<fo:block-container break-before=“page”

But when I render the files, the layout if off. I think it is because the xls file is build for a resolution of 75 DPI, but Aspose defualt is rendering it with 150 DPI?

Is there any way I can change the resolution to 75DPI when the xml and xls file is rendered to a pdf file?


Thanks for your feedback.

The basic unit of measurement in Aspose.PDF is Point where 72 Points = 1 inch. You can specify value in points as per your requirements and in case you still face any issue in rendered PDF, please share your sample files with us along with expected PDF document. We will test the scenario in our environment and address it accordingly.

Here are the c# code i am using:

string resultContent = result.Result.Content.ReadAsStringAsync().Result;
XmlDocument xDoc = new XmlDocument();
//var path = System.Web.HttpContext.Current.Server.MapPath("~/App_Code/Class/Transport/TNT/XLS_RenderFiles/PDFRoutingLabelRenderer.xsl");
var path = @“C:\Temp\Renderfiles\PDFRoutingLabelRenderer.xsl”;
Stream XMLstream = new MemoryStream();
XMLstream.Position = 0;

                // Initialize license object
                Aspose.Pdf.License license = new Aspose.Pdf.License();
                // Set license
                Stream fs = File.OpenRead(path);
                 // Load PDF document
                   Document pdfDocument = new Document(XMLstream, new XslFoLoadOptions(fs));
                    pdfDocument.Save(@"c:/temp/output.pdf", SaveFormat.Pdf);


I have attached the xls files, the input xml and a pdf documnet of what it should look like when it is merged.

7100035864 - Label.pdf (29.1 KB)

Renderfiles.zip (85.4 KB)


Would you please confirm if shared code snippet is working fine at your end. We have tried your code snippet in our environment with following modifications but it threw an exception of root element is not present.

System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.LoadXml(File.ReadAllText(dataDir + "Renderfiles\\input.xsl"));
var path = dataDir + "Renderfiles\\PDFRoutingLabelRenderer.xsl";
Stream XMLstream = new MemoryStream();
XMLstream.Position = 0;
Stream fs = File.OpenRead(path);
Document pdfDocument = new Document(XMLstream, new XslFoLoadOptions(fs));
pdfDocument.Save(dataDir + @"output.pdf", SaveFormat.Pdf);

We also tried following code snippet, but it produced an invalid PDF file.

pdfDocument.BindXml(dataDir + "Renderfiles\\input.xml", dataDir + "Renderfiles\\PDFRoutingLabelRenderer.xsl");

Would you please confirm if you are facing similar issues. We will further log these details in our issue tracking system and share the ID with you.

If I use your codesnippet then I et an exception of missing root element. If I use my own code and read it directly from the stream, then it is working, but there are something wrong with the DPI settings, so all lines are off.

How can I set the DPI?output.pdf (269.8 KB)

I have uploaded pdf with my result.


Thanks for your response.

Could you please try after modifying above tag as followings and in case this does not resolve your issue, please let us know. We will further proceed to help you out.

<fo:block-container break-before=“page”