InsertVideoLink.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Diagnostics;
  10. using GrapeCity.Documents.Word;
  11. using GrapeCity.Documents.Imaging;
  12.  
  13. namespace DsWordWeb.Demos
  14. {
  15. // This demo shows how to insert a link to a YouTube video into an existing DOCX.
  16. public class InsertVideoLink
  17. {
  18. public GcWordDocument CreateDocx()
  19. {
  20. var doc = new GcWordDocument();
  21. // Load an existing DOCX and find a specific location in it:
  22. doc.Load(Path.Combine("Resources", "WordDocs", "wetlands.docx"));
  23. var fr = doc.Body.Find("Reptiles and amphibians must return there to breed").First();
  24. // Add picture with a thumbnail and a video link after the found paragraph:
  25. var par = fr.Range.ParentParagraph.Next;
  26. var pic = par.AddRun().AddPicture();
  27. var picBytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "wetlands.jpg"));
  28. pic.ImageData.SetImage(picBytes, "image/jpeg");
  29. pic.ImageData.WebVideoProperties.SetUrl("https://www.youtube.com/watch?v=k9UbKlBc3W4", "What are wetlands", 420, 300);
  30. pic.Size.Width.Value = 400;
  31. pic.Size.Height.Value = 300;
  32. // Done:
  33. return doc;
  34. }
  35. }
  36. }
  37.