//
// 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 System.Linq;
using System.Diagnostics;
using GrapeCity.Documents.Word;
using GrapeCity.Documents.Imaging;
namespace DsWordWeb.Demos
{
// This demo shows how to insert a link to a YouTube video into an existing DOCX.
public class InsertVideoLink
{
public GcWordDocument CreateDocx()
{
var doc = new GcWordDocument();
// Load an existing DOCX and find a specific location in it:
doc.Load(Path.Combine("Resources", "WordDocs", "wetlands.docx"));
var fr = doc.Body.Find("Reptiles and amphibians must return there to breed").First();
// Add picture with a thumbnail and a video link after the found paragraph:
var par = fr.Range.ParentParagraph.Next;
var pic = par.AddRun().AddPicture();
var picBytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "wetlands.jpg"));
pic.ImageData.SetImage(picBytes, "image/jpeg");
pic.ImageData.WebVideoProperties.SetUrl("https://www.youtube.com/watch?v=k9UbKlBc3W4", "What are wetlands", 420, 300);
pic.Size.Width.Value = 400;
pic.Size.Height.Value = 300;
// Done:
return doc;
}
}
}