PictureAdd.vb
''
'' This code is part of GrapeCity Documents for Word samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Word
Imports 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 Function
End Class