'' This code is part of GrapeCity Documents for Word samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports System.Data
Imports System.Linq
Imports GrapeCity.Documents.Word

'' This sample shows how to use the image formatter in a data template.
Public Class DataTplImage
    Function CreateDocx() As GcWordDocument
        '' The data source.
        '' The 'imagePath' yields the absolute path of an image,
        '' which Is one of accepted value types for the image formatter.
        '' For reference, the following value types are supported by the image formatter:
        '' - A byte array containing the image data
        '' - A System.IO.Stream object that can be used to read the image data
        '' - A System.Drawing.Image object
        '' - A string from which an absolute file URI of the image can be created, Or Base64-encoded image data.
        Dim data =
                New With {.name = "Minerva", .imagePath = Path.GetFullPath(Path.Combine("Resources", "Images", "minerva.jpg"))},
                New With {.name = "Colosseum", .imagePath = Path.GetFullPath(Path.Combine("Resources", "Images", "colosseum.jpg"))},
                New With {.name = "Venus Felix", .imagePath = Path.GetFullPath(Path.Combine("Resources", "Images", "lady.jpg"))}

        Dim doc = New GcWordDocument()

        '' Add the data source to the data template data sources
        '' (note that in this release, only one data source can be added):
        doc.DataTemplate.DataSources.Add("ds", data)

        '' The single paragraph added to the document contains template tags
        '' - {{#ds}}..{{/ds}} -- root template, 'ds' is the name of the data source
        '' - {{}} -- fetches the image name
        '' - {{ds.imagePath}:image(266,400)} -- fetches the image file, resizes the image to specified size.
        Dim p = doc.Body.Paragraphs.Add("{{#ds}}{{}}:" + vbCrLf + "{{ds.imagePath}:image(266,400)}{{/ds}}")

        '' This call expands all data templates in the document,
        '' replacing template tags with data (iterating over all data items):

        '' Done
        Return doc
    End Function
End Class