Created
March 8, 2024 11:51
-
-
Save conholdate-gists/535941cd78801c54a926c2e3ecf0b6bc to your computer and use it in GitHub Desktop.
Convert XML to PDF in C# .NET
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
// Instantiate Document object | |
Document doc = new Document(); | |
// Bind source XML file | |
doc.BindXml(dataDir + "input.xml"); | |
// Convert XML to PDF | |
doc.Save(dataDir + "XMLToPDF.pdf"); |
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 pdf document | |
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(); | |
//Bind XML and XSLT files | |
try | |
{ | |
pdf.BindXml("hello-world.xml", "hello-world.xslt"); | |
} | |
catch (System.Exception) | |
{ | |
throw; | |
} | |
//Save the document | |
pdf.Save("HelloWorldXml.pdf"); |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<Document xmlns="Aspose.Pdf"> | |
<Page id="mainPage"> | |
<TextFragment> | |
<TextSegment>Hello</TextSegment> | |
</TextFragment> | |
<TextFragment> | |
<TextSegment>World!</TextSegment> | |
</TextFragment> | |
</Page> | |
</Document> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment