Create a Hello World PDF document through XML and XSLT

Skip to end of metadata
Go to start of metadata
Sometimes you may have existing XML files that contain application data and you want to generate PDF report using these files. You can use XSLT to transform your existing XML document to Aspose.Pdf's compatible XML document and then generate PDF file. There are 3 steps to generate PDF using XML and XSLT.

Please follow these steps to convert an XML file into a PDF document using XSLT:

  • Create an instance of Pdf class that represents a PDF document
  • If you have purchased a license then you should also embed the code to use that license with the help of License class in Aspose.Pdf namespace
  • Bind the input XML and XSLT files to the instance of Pdf class by calling its BindXML method
  • Save the bound XML with Pdf instance as a PDF document

Code Snippet

XML
<?xml version="1.0" encoding="utf-8" ?> 
  <Contents> 
          <Content>Hello World</Content> 
  </Contents>
 
XSLT
<?xml version="1.0" encoding="utf-8" ?> 
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
   <xsl:template match="text()" />
    <xsl:template match="/Contents">
     <Pdf xmlns="Aspose.Pdf"> 
      <Section>
              <Text ID="Text1">
                         <Segment><xsl:value-of select="Content"/></Segment>
         </Text> 
      </Section> 
     </Pdf> 
    </xsl:template> 
  </xsl:stylesheet>
 
C#
//Create pdf document
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Instantiate License class and call its SetLicense method to use the license
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Pdf.lic");

//Bind XML and XSLT files to the document
pdf1.BindXML("../HelloWorld-Content.XML","../HelloWorld.xslt");

//Save the document
pdf1.Save("HelloWorld.pdf");
 
VB.NET
'Create pdf document
Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()

'Instantiate License class and call its SetLicense method to use the license
Dim license As license = New license
License.SetLicense("Aspose.Pdf.lic")

'Bind XML and XSLT files to the document
pdf1.BindXML("../HelloWorld-Content.XML", "../HelloWorld.xslt")

'Save the document
pdf1.Save("HelloWorld.pdf")
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.