Home

PDFDoc Scout

PDFDoc Scout screenshot (click to enlarge)



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

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 also XML to PDF example for Visual C# 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:

Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials  |  News |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement