PictureAdd.cs
- //
- // This code is part of Document Solutions for Word demos.
- // Copyright (c) MESCIUS inc. All rights reserved.
- //
- using System;
- using System.IO;
- using System.Drawing;
- using GrapeCity.Documents.Word;
- using GrapeCity.Documents.Imaging;
-
- namespace DsWordWeb.Demos
- {
- // This sample demonstrates how to add a JPEG image to a document.
- public class PictureAdd
- {
- public GcWordDocument CreateDocx()
- {
- GcWordDocument doc = new GcWordDocument();
-
- // Load picture data:
- var picBytes = File.ReadAllBytes(Path.Combine("Resources", "Images", "road.jpg"));
- // Create a GcBitmap so that we can find out the native picture size:
- var image = new GcBitmap(picBytes);
- // Scale picture size to fill the width of the page:
- var width = doc.Body.Sections.Last.PageSetup.ClientWidth;
- var height = image.Height * (width / image.Width);
-
- // Add an inline picture that fills the page width:
- var pars = doc.Body.Sections.First.GetRange().Paragraphs;
- var par = pars.Add("Picture sized to fill the page:");
- var run = par.GetRange().Runs.Last;
- run.GetRange().Texts.AddBreak();
- // Add picture, specifying its mime type:
- var pic = run.GetRange().Pictures.Add(picBytes, "image/jpeg");
- pic.Size.Width.Value = width;
- pic.Size.Height.Value = height;
-
- pars.Add("The End.");
-
- // Done:
- return doc;
- }
- }
- }
-