PictureAdd.vb
C# VB
'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports SystemImports System.IOImports GrapeCity.Documents.WordImports GrapeCity.Documents.Imaging
'' This sample demonstrates how to add a JPEG image to a document.Public Class PictureAdd Function CreateDocx() As GcWordDocument Dim doc = New GcWordDocument()
'' Load picture data Dim picBytes = File.ReadAllBytes(Path.Combine("Resources", "Images", "road.jpg")) '' Create a GcBitmap so that we can find out the native picture size Dim image = New GcBitmap(picBytes) Dim width = doc.Body.Sections.Last.PageSetup.ClientWidth Dim height = image.Height * (width / image.Width)
'' Add an inline picture that fills the page width Dim pars = doc.Body.Sections.First.GetRange().Paragraphs Dim par = pars.Add("Picture sized to fill the page:") Dim Run = par.GetRange().Runs.Last Run.GetRange().Texts.AddBreak() '' Add picture, specifying its mime type Dim pic = Run.GetRange().Pictures.Add(picBytes, "image/jpeg") '' Scale picture size to fill the width of the page pic.Size.Width.Value = width pic.Size.Height.Value = height
pars.Add("The End.")
'' Done Return doc End FunctionEnd Class