Read the complete article on XML to PDF conversion in Java: https://blog.aspose.com/2021/06/30/convert-xml-to-pdf-using-java/
Last active
July 1, 2021 04:34
-
-
Save aspose-com-gists/a7599829acc2abcd7b08e66f8d41b948 to your computer and use it in GitHub Desktop.
Convert XML to PDF in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<Contents> | |
<Content>Hello World!</Content> | |
</Contents> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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