Aspose.Pdf

Create a Hello World PDF document through XML and XSLT

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:

 

 

Code Snippet

 

[Input XML File]

 

<?xml version="1.0" encoding="utf-8" ?>

  <Contents>

          <Content>Hello World</Content>

  </Contents>

 

[Input XSLT File]

 

<?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

Pdf pdf1 = new 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 Pdf = New 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")