VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Merge Xml Files in PDF Document & Reduce Code Duplication

by Aspose (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Tue 15th March 2011
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



 
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>



Download this snippet    Add to My Saved Code

Merge Xml Files in PDF Document & Reduce Code Duplication Comments

No comments have been posted about Merge Xml Files in PDF Document & Reduce Code Duplication. Why not be the first to post a comment about Merge Xml Files in PDF Document & Reduce Code Duplication.

Post your comment

Subject:
Message:
0/1000 characters