SvgSpecArt.vb
''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Linq
Imports System.Collections.Generic
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Svg
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' Use GcSvgDocument to render a few images used as illustrations
'' in the SVG spec.
Public Class SvgSpecArt
    Function CreatePDF(ByVal stream As Stream) As Integer
        '' Load images from resources:
        Dim fnames = New List(Of String)() From {"dash-path.svg", "opacity.svg", "paths.svg", "shadowstyle.svg", "units.svg"}
        Dim images = New List(Of (String, GcSvgDocument))()
        For Each f In fnames
            images.Add((f, GcSvgDocument.FromFile(Path.Combine("Resources", "SvgSpecArt", f))))
        Next

        Const margin As Single = 36
        Const gapy As Single = 18
        Dim ip = New PointF(margin, margin)

        '' Render the images:
        Dim doc = New GcPdfDocument()
        Dim g = doc.NewPage().Graphics
        For i = 0 To images.Count - 1
            Dim svg = images(i).Item2
            Dim s = svg.GetIntrinsicSize(SvgLengthUnits.Points)
            g.DrawSvg(svg, ip)
            ip.Y += s.Height + gapy
        Next

        '' Done:
        doc.Save(stream)
        '' Dispose images after saving the PDF:
        images.ForEach(Sub(t_) t_.Item2.Dispose())
        Return doc.Pages.Count
    End Function
End Class