AddSvg.cs
C# VB
//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.IO;using System.Diagnostics;using GrapeCity.Documents.Word;
namespace DsWordWeb.Demos{ // This demo shows how to add an SVG image to am MS Word DOCX document. public class AddSvg { public GcWordDocument CreateDocx() { var doc = new GcWordDocument(); var 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.");
var pic = doc.Body.AddParagraph().AddRun().AddPicture(); // Load picture data: var 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 != null); Debug.Assert("image/png" == pic.ImageData.ContentType); Debug.Assert(pic.ImageData.ComplementaryVectorData != null); 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; } }}