Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 1, 2021 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/a7599829acc2abcd7b08e66f8d41b948 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/a7599829acc2abcd7b08e66f8d41b948 to your computer and use it in GitHub Desktop.
Convert XML to PDF in Java
<?xml version="1.0" encoding="utf-8" ?>
<Contents>
<Content>Hello World!</Content>
</Contents>
<?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">
<html>
<Document xmlns="Aspose.Pdf" IsAutoHyphenated="false">
<PageInfo>
<DefaultTextState Font = "Helvetica" FontSize="8" LineSpacing="4"/>
<Margin Left="5cm" Right="5cm" Top="3cm" Bottom="15cm" />
</PageInfo>
<Page id="mainSection">
<TextFragment>
<TextSegment>
<xsl:value-of select="Content"/>
</TextSegment>
</TextFragment>
</Page>
</Document>
</html>
</xsl:template>
</xsl:stylesheet>
// Create a new PDF document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document();
// Transform and bind XML
pdfDocument.bindXml( "data.xml", "stylesheet.xslt");
// Generate PDF from XML
pdfDocument.save( "generated-pdf.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment