''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Diagnostics
Imports GrapeCity.Documents.Word
'' This demo shows how to add an SVG image to am MS Word DOCX document.
Public Class AddSvg
Function CreateDocx() As GcWordDocument
Dim doc = New GcWordDocument()
Dim par = doc.Body.AddParagraph("The picture below is produced by a vector SVG image added to the document. " +
"Mimicking the MS Word behavior, when an SVG is added, DsWord also creates a fallback raster version of the image.")
Dim pic = doc.Body.AddParagraph().AddRun().AddPicture()
'' Load picture data:
Dim picBytes = File.ReadAllBytes(Path.Combine("Resources", "SVG", "Smiling-Girl.svg"))
pic.ImageData.SetImage(picBytes, "image/svg+xml")
'' In a debug configuration this shows that both vector and raster image versions are present:
Debug.Assert(pic.ImageData.ImageBytes IsNot Nothing)
Debug.Assert("image/png" = pic.ImageData.ContentType)
Debug.Assert(pic.ImageData.ComplementaryVectorData IsNot Nothing)
Debug.Assert(pic.ImageData.ComplementaryVectorData.ImageBytes.Length > 0)
Debug.Assert("image/svg+xml" = pic.ImageData.ComplementaryVectorData.ContentType)
'' Specify the picture size:
pic.Size.Width.Value = 200
pic.Size.Height.Value = 400
doc.Body.AddParagraph("The End.")
'' Done:
Return doc
End Function
End Class