Merge Xml Files in PDF Document & Reduce Code Duplication
Merge Xml Files in PDF Document & Reduce Code Duplication
API Declarations
An example code snippet is demonstrated below that uses an XSLT file using XslTransform class to combine the shared content from different XML files and produce a combined XML file that is then bound to Pdf object by calling its BindXML method. After the final XML file is bound then it can be saved as a PDF document by calling save method of the Pdf class.
More about Aspose.Pdf for .NET
- Homepage of Aspose.Pdf for .NET: http://www.aspose.com/categories/.net-components/aspose.pdf-for-.net/default.aspx
- Read more technical tips by Aspose.Pdf for .NET: http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/index.html
- Download Aspose.Pdf for .NET at: http://www.aspose.com/community/files/51/.net-components/aspose.pdf-for-.net/default.aspx
Rate Merge Xml Files in PDF Document & Reduce Code Duplication
(1(1 Vote))
FileStream fs1 = new FileStream(@"D:\AsposeTest\Example.xml", FileMode.Open);
FileStream fs2 = new FileStream(@"D:\AsposeTest\Example.xslt", FileMode.Open);
Pdf pdf1 = new Pdf();
pdf1.BindXML(fs1, fs2);
pdf1.Save("D:/Asposetest/XMlXSLTMERGE.pdf");
fs1.Close();
fs2.Close();
Example: .Net Framework 1.1 and VS 2003
[C#]
XmlDocument xmlDoc = new XmlDocument();
MemoryStream ms = new MemoryStream();
XslTransform xsl = new XslTransform();
xsl.Load("test.xslt");
xsl.Transform(xmlDoc,null,ms);
ms.Position = 0;
xmlDoc.Load(ms);
ms.Close();
Pdf pdf = new Pdf();
pdf.BindXML(xmlDoc,null);
pdf.Save("e:/temp/test.pdf");
[VB.NET]
Dim xmlDoc As XmlDocument = New XmlDocument()
Dim ms As MemoryStream = New MemoryStream()
Dim xsl As XslTransform = New XslTransform()
xsl.Load("test.xslt")
xsl.Transform(xmlDoc, Nothing, ms)
ms.Position = 0
xmlDoc.Load(ms)
ms.Close()
Dim pdf As Pdf = New Pdf()
pdf.BindXML(xmlDoc, Nothing)
pdf.Save("e:/temp/test.pdf")
[test.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="/">
<Pdf xmlns="Aspose.Pdf">
<Section>
<Header>
<xsl:copy-of select="document('header.xml')"/>
</Header>
<xsl:copy-of select="document('content.xml')"/>
</Section>
</Pdf>
</xsl:template>
</xsl:stylesheet>
[header.xml]
<Text>
<Segment>header</Segment>
</Text>
[content.xml]
<Text>
<Segment>Hello world</Segment>
</Text>
Merge Xml Files in PDF Document & Reduce Code Duplication Comments
No comments yet — be the first to post one!
Post a Comment