Ref :http://bytescout.com/pdfdocscout_example_xml_xslt_transformation_to_pdf_csharp.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace XMLtoPDFUsingPDFDocScout
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnXMLToPDF_Click(object sender, EventArgs e)
{
// Transform XML using XSLT and get HTML code
// then create PDF document from produced HTML code
PDFDocScout.PDFDocument PDFDoc = new PDFDocScout.PDFDocument();
PDFDoc.InitLibrary ("demo", "demo");
PDFDoc.OutputFileName = "XML2HTML.pdf";
PDFDoc.AutoOpenGeneratedPDF = true;
PDFDoc.BeginDocument();
// load source XML document
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(boxXML.Text);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(boxXSLT.Text);
// create XML doc to store result of transformation
XmlDocument objResultXML = new XmlDocument();
//Transform the XML using XLST into HTML (produced HTML is written to writer object)
StringWriter writer = new StringWriter();
xslt.Transform(new XPathDocument(boxXML.Text), null, writer);
writer.Close();
// convert produced HTML code into PDF
PDFDoc.Page.AddHTMLBox (writer.ToString(), 0,0, PDFDoc.Page.Width, PDFDoc.Page.Height, true);
PDFDoc.EndDocument(); // close PDF document generation
}
}
}