Free Support Forum -

Generate PDF using xml data and xsl


In my requirement data should split into 2 columns in same page(left to right and top to botton but in 2 columns) if data both columns are filed then data should appear on next page…
Please share the code and approach using (255.8 KB)



Thank you for contacting support.

Aspose.PDF for .NET 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 order to convert XML file into PDF, please visit following article(s) in our API documentation:

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


Thanks Farhan,
I have tried above code snippet but pdf is blank and getting error (please check attached snapshot)
data.PNG (8.9 KB)

I have used below XSL -

<?xml version="1.0" encoding="UTF-16" ?>

<xsl:stylesheet version=“1.0” xmlns:fo=“
<xsl:output method=“xml” version=“1.0” indent=“yes” />
<xsl:template match=“doc”>
<fo:root xmlns:fo=“”>
<fo:simple-page-master page-height=“297mm” page-width=“210mm”
margin=“5mm 25mm 5mm 25mm” master-name=“PageMaster”>
<fo:region-body margin=“20mm 0mm 20mm 0mm” column-count=“2”/>
<fo:simple-page-master master-name=“intro”>
<fo:region-body margin=“5in” />
<fo:simple-page-master master-name=“left”>
<fo:region-body margin-left=“2in” margin-right=“3in” />
<fo:simple-page-master master-name=“right”>
<fo:region-body margin-left=“3in” margin-right=“2in” />
<fo:page-sequence master-reference=“PageMaster”>
<fo:flow flow-name=“xsl-region-body” >

<xsl:template match=“p”>
<fo:block font-weight=“bold” background-color=“red” color=“blue”>
<xsl:apply-templates />
<xsl:template match=“b”>
<fo:inline font-weight=“bold” background-color=“red” color=“blue”>
<xsl:apply-templates />
</xsl:stylesheet >

------------------------------------XML used -------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-16" ?> Simple

Hello World!

This is the firstSimpleDoc

while copy paste XSL and XML content is not appearing properly please check attached snapshots2.PNG (8.6 KB)
1.PNG (53.5 KB)



Please note that the XML shared by you does not follow Aspose.PDF for .NET XML Schema so the issue is occurring. Kindly ensure sequence of elements in accordance with schema and then share your kind feedback with us.


Thank you so much…Can you please share your Skype ID? or you can connect me on

If possible share the updated XML of above attached XML.



Please note that support is offered via forums only so we may not contact you over other platforms. Moreover, a basic and Hello World level XML is already available in the documentation article Generate PDF from XML for your kind reference.


Thank you for reply

To generate the PDF, I have tried 2 approaches-

  1. Transformed XML data with XSL and converted into HTML then Using Aspose.HTML, converted HTML to PDF(It’s working as expected using same .xml and .xsl files)

  2. When I am trying to use Aspose.PDF please check below code. Pdf is generating and is not opening because it’s blank pdf. Even I have used same xml which suggested by you (
    and try to generate PDF using XML only it’s generating BLANK PDF.

Please share valid SAMPLE XML and XSL which follow Aspose.PDF for .NET XML Schema
so I can use below code for my requirement.

Document pdf = new Document();

        using (FileStream fs1 = new FileStream(xmlpath + "Examples.xml", FileMode.Open))
        using (FileStream fs2 = new FileStream(xmlpath + "Examples.xsl", FileMode.Open))
            // Bind the XML file
            pdf.BindXml(fs1, fs2);
            // Save the resultant PDF
            pdf.Save(xmlpath + "Examples.pdf");

I am achieving requirement using first approach but I don’t have ASPOSE.Html lic but I have for ASPOSE.Pdf.lic

Thanks in advance



Please find attached below files for your kind reference. Attached PDF file has been generated with your code snippet.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


Thank you so much for help. It’s working fine.


Hi @Farhan.Raza,

When I am trying to use Table in C# code,Table count is showing ZERO. Please look into below code. I have to apply colspan =2 on cell. I am using same XML and XSL which you shared above.

     Document pdf = new Document();
      // Bind the XML file
       pdf.BindXml(xmlpath + "DemoXml.xml", xmlpath + "DemoXslt.xsl");
        TableAbsorber absorber = new TableAbsorber();
         foreach (AbsorbedTable table in absorber.TableList)

I am using ASPOSE 18.12 version

Thank you for quick assistance.
sss.PNG (41.6 KB)ttt.PNG (24.2 KB)



We have been able to notice the problem when extracting the table from generated PDF document. A ticket with ID PDFNET-45892 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.


Thanks to let me know.

Please share the estimated time till when it will resolve or I have to try other option to achive same.
Any other stable ASPOSE PDF version where I can get Table and cell.

Thanks again for assistance



Please note that support is provided based on latest version of the API because of it being the most stable version. About investigations of recently logged ticket, it will be scheduled on its due turn which may take few months owing to previously logged tickets. We will let you know as soon as some significant updates will be available.


Hi Farhan,

Thanks to update.
Can you please help on below requirement? How can I achieve using ASPOSE PDF?

otherwise I have to go with other PDF generation approaches.

Thanks again for assistance.



Please always create separate posts for separate requirements.

Would you please share source XML and XSL file along with a PDF document as expected output from that data, so that we may investigate further to help you out.

#16 (54.4 KB)
Please find the attached XML, XSL , HTML and output PDF.
I am using below c# code -

using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.Core.Entities;
using TheArtOfDev.HtmlRenderer.PdfSharp;

string myStyleSheet = xmlpath + “Component.xsl”;
string myhtml = xmlpath + “Component.html”;

XPathDocument myXPathDoc = new XPathDocument(xmlpath + “Component.xml”);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
using (XmlTextWriter myWriter = new XmlTextWriter(myhtml, null))
myXslTrans.Transform(myXPathDoc, null, myWriter);
string html = File.ReadAllText(myhtml);
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A3, 15, null, null, imageLoad: OnImageLoad);

pdf.Save(xmlpath + “Component.pdf”);

2nd approach I have tried using Aspose.HTML instead of PdfSharp

Next time will create separate thread for different requirement, Please suggest how to get the multicolumn text flow in html using Aspose.



Thank you for elaborating it further.

We would like to update you that once you generate the HTML file using System.XML namespace, you can also use Aspose.PDF for .NET API to convert that HTML file into a PDF document using below code snippet.

HtmlLoadOptions options = new HtmlLoadOptions();
Document document = new Document(myhtml , options);
document.Save(xmlpath + "Aspose_19.1.pdf");

Moreover, if you want to generate a multiple column PDF document from your HTML file then you may use below code snippet and then share your kind feedback.

string html = File.ReadAllText(dataDir + "Component.html");
Document doc = new Document();
// Specify the left margin info for the PDF file
doc.PageInfo.Margin.Left = 40;
// Specify the Right margin info for the PDF file
doc.PageInfo.Margin.Right = 40;
Aspose.Pdf.Page page = doc.Pages.Add();

Aspose.Pdf.Drawing.Graph graph1 = new Aspose.Pdf.Drawing.Graph(500, 2);
// Add the line to paraphraphs collection of section object

// Specify the coordinates for the line
float[] posArr = new float[] { 1, 2, 500, 2 };
Aspose.Pdf.Drawing.Line l1 = new Aspose.Pdf.Drawing.Line(posArr);
// Create string variables with text containing html tags

string s = "<font face=\"Times New Roman\" size=4>" +

"<strong> How to Steer Clear of money scams</<strong> "
+ "</font>";
// Create text paragraphs containing HTML text

HtmlFragment heading_text = new HtmlFragment(s);

Aspose.Pdf.FloatingBox box = new Aspose.Pdf.FloatingBox();
// Add four columns in the section
box.ColumnInfo.ColumnCount = 2;
// Set the spacing between the columns
box.ColumnInfo.ColumnSpacing = "5";

box.ColumnInfo.ColumnWidths = "105 105";
TextFragment text1 = new TextFragment("By A Googler (The Official Google Blog)");
text1.TextState.FontSize = 8;
text1.TextState.LineSpacing = 2;
text1.TextState.FontSize = 10;

text1.TextState.FontStyle = FontStyles.Italic;
// Create a graphs object to draw a line
Aspose.Pdf.Drawing.Graph graph2 = new Aspose.Pdf.Drawing.Graph(50, 10);
// Specify the coordinates for the line
float[] posArr2 = new float[] { 1, 10, 100, 10 };
Aspose.Pdf.Drawing.Line l2 = new Aspose.Pdf.Drawing.Line(posArr2);

// Add the line to paragraphs collection of section object

HtmlFragment text2 = new HtmlFragment(html);


dataDir = dataDir + "CreateMultiColumnPdf_19.1.pdf";
// Save PDF file

You may also visit Create Multi-Column PDF document for your kind reference. Above code snippet creates a PDF document having two columns on each page as a demonstration. You may modify size or number of columns as per your requirements.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.