Home
We need your feedback!

PDFDoc Scout

PDFDoc Scout screenshot (click to enlarge)


Subscribe to Our Bi-Monthly Newsletter (tips, new releases, specials):
 Subscribe in a reader
 PRODUCTS  |  DOWNLOAD  |  PURCHASE  |  SUPPORT  |  TESTIMONIALS   |  NEWS  | 

PDFDoc Scout library - Sample

Download Free Trial See Licensing Options More Information

How to convert XML into PDF using XSLT template transformation


See also: XML to PDF example for Visual C# here
XML to PDF example for VB.NET here

You can download the source code of this example (VBScript) here:
pdfdocscout_xml_xslt_transformation_example.zip

This example describes how to transform XML into PDF document using XSLT (.xsl) template using PDFDoc Scout library

Source XML data (simpsons.xml):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Simpsons.xsl"?>
<Simpsons>
<FamilyMember>Homer Jay Simpson</FamilyMember>
<FamilyMember>Marjorie Marge Simpson (Bouvier)</FamilyMember>
<FamilyMember>Bartholomew Jojo Bart Simpson</FamilyMember>
<FamilyMember>Lisa Marie Simpson</FamilyMember>
<FamilyMember>Margaret Maggie Simpson</FamilyMember>
<ExtendedFamilyMember>Abraham Jay Simpson</ExtendedFamilyMember>
<ExtendedFamilyMember>Mona J. Simpson</ExtendedFamilyMember>
<ExtendedFamilyMember>Jacqueline Ingrid Bouvier</ExtendedFamilyMember>
<ExtendedFamilyMember>Clancy Bouvier</ExtendedFamilyMember>
<ExtendedFamilyMember>Patricia "Patty" Bouvier</ExtendedFamilyMember>
</Simpsons>

XSLT template (simpsons.xsl):

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="FamilyMember">
<p><b><u><xsl:value-of select="."/></u></b></p>
</xsl:template>

<xsl:template match="ExtendedFamilyMember">
<p><i><xsl:value-of select="."/></i></p>
</xsl:template>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Produced PDF document (XML2HTML.pdf generated from source Simpsons.xml XML data)

PDF document produced from transformed XML simpsons.xml

Code to transform XML and convert into PDF using PDFDoc Scout lib:

' Transform XML using XSLT and get HTML code
' then create PDF document from produced HTML code

Set PDFDoc = CreateObject("PDFDocScout.PDFDocument")

PDFDoc.InitLibrary "demo", "demo"
PDFDoc.OutputFilename = "XML2HTML.pdf"
PDFDoc.AutoOpenGeneratedPDF = true

PDFDoc.BeginDocument

' load source XML document
Set xmlDocument = CreateObject("Msxml2.DOMDocument.4.0")
xmlDocument.async = false
xmlDocument.load("Simpsons.xml")

' load XSLT template
Set xslDocument = CreateObject("Msxml2.DOMDocument.4.0")
xslDocument.async = false
xslDocument.load("Simpsons.xsl")

' create XML doc to store result of transformation
Set objResultXML = CreateObject("Msxml2.DOMDocument.4.0")
objResultXML.async = false
objResultXML.validateOnParse = true

' transform XML using XSLT into objResultXML document
xmlDocument.transformNodeToObject xslDocument, objResultXML

' convert produced HTML code from objResultXML document into PDF
PDFDoc.Page.AddHTMLBox objResultXML.xml, 0,0, PDFDoc.Page.Width, PDFDoc.Page.Height, true

PDFDoc.EndDocument ' close PDF document generation

' disconnect from library
Set PDFDoc = Nothing

You can download the source code of this example (VBScript) here:
pdfdocscout_xml_xslt_transformation_example.zip

See examples for other languages:
XML to PDF example for Visual C# here
XML to PDF example for VB.NET here
Download Free Trial See Licensing Options More Information


See also: Bytescout.PDF - native .NET library to write/read/sign/
modify/merge/split PDF documents (but no HTML2PDF support)



On-line documentation (HTML format)


"Hello, World!" quick start step-by-step tutorials:


HOME  |  CONTACT US

Copyright © ByteScout, 2003-2010. Privacy Statement
Microsoft®, Windows®, Windows 2000®, Windows Server®, Windows Vista®, Internet Explorer®, .NET Framework®, ActiveX®, Visual Basic®, Visual C#®, ASP®, ASP.NET®, Excel®, PowerPoint®, are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Adobe®, Flash® and Acrobat® are registered trademarks of Adobe Systems, Incorporated. Mozilla®, Firefox® and the Mozilla and Firefox Logos are registered trademarks of the Mozilla Foundation. Other product names or brandnames used herein are for identification purposes only and might be trademarks or registered trademarks of their respective companies. We disclaim any and all rights to those marks.