'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.Collections.GenericImportsSystem.DataImportsSystem.LinqImportsSystem.ReflectionImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Html '' This sample shows how to render a report (the list of products'' from the standard NWind sample database) using a {{mustache}}'' HTML template.'''' The data query and HTML formatting are similar to those used'' in the ProductList sample. Unlike that sample though, here'' we use the HTML template file ProductListTemplate.html'' loaded from a resource, and bind it to data using {{mustache}}.'' Changing the template file (preserving the {{mustache}} bindings)'' can be used to easily customize the look of the report.'''' This sample uses the Stubble.Core package to bind data to the template.'''' Please see notes in comments at the top of HelloWorldHtml'' sample code for details on adding DsHtml to your projects.PublicClassProductListTemplateSubCreatePDF(ByVal stream AsStream)Using ds = NewDataSet()'' Fetch data: ds.ReadXml(Path.Combine("Resources", "data", "DsNWind.xml")) Dim dtProds = ds.Tables("Products")Dim dtSupps = ds.Tables("Suppliers") Dim products =From prod In dtProds.Select()Join supp In dtSupps.Select()On prod("SupplierID") Equals supp("SupplierID")OrderBy prod("ProductName")SelectNewWith { .ProductID = prod("ProductID"), .ProductName = prod("ProductName"), .Supplier = supp("CompanyName"), .QuantityPerUnit = prod("QuantityPerUnit"), .UnitPrice = $"{prod("UnitPrice"):C}" } '' Load the template - HTML file with {{mustache}} data references:Dim template = File.ReadAllText(Path.Combine("Resources", "Misc", "ProductListTemplate.html"))'' Bind the template to data:Dim builder = NewStubble.Core.Builders.StubbleBuilder()'' Render the bound HTML:Dim boundTemplate = builder.Build().Render(template, NewWith {.Query = products})Dim tmp = Path.GetTempFileName()'' Create an instance of GcHtmlBrowser that is used to render HTML:Using browser = Util.NewHtmlBrowser()'' PdfSettings specifies options for HTML to PDF conversion:Dim pdfOptions = NewPdfOptions() With { .Margins = NewPdfMargins(0.2F, 1, 0.2F, 1), .DisplayHeaderFooter = True, .HeaderTemplate = "<div style='color:#1a5276 font-size:12px width:1000px margin-left:0.2in margin-right:0.2in'>" +"<span style='float:left'>Product Price List</span>" +"<span style='float:right'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></span>" +"</div>", .FooterTemplate = "<div style='color: #1a5276 font-size:12em width:1000px margin-left:0.2in margin-right:0.2in'>" +"<span>(c) MESCIUS inc. All Rights Reserved.</span>" +"<span style='float:right'>Generated on <span class='date'></span></span></div>" }'' Render the generated HTML to the temporary file:Using htmlPage = browser.NewPage(boundTemplate) htmlPage.SaveAsPdf(tmp, pdfOptions)EndUsingEndUsing'' Copy the created PDF from the temp file to target streamUsing ts = File.OpenRead(tmp) ts.CopyTo(stream)EndUsing'' Clean up:File.Delete(tmp)EndUsing'' Done.EndSubEndClass