AddVideoLink.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 add a link to a YouTube video that plays in the DOCX.
  16. public class AddVideoLink
  17. {
  18. public GcWordDocument CreateDocx()
  19. {
  20. var doc = new GcWordDocument();
  21. doc.Body.AddParagraph("The picture below includes a link to a YouTube video which plays inside the document if clicked.");
  22. // Add picture with a thumbnail and a video link inside:
  23. var vStyle = doc.Styles.Add("vlink_style", doc.Styles[BuiltInStyleId.BlockText]);
  24. vStyle.ParagraphFormat.Indentation.LeftIndent = 0;
  25. var par = doc.Body.AddParagraph();
  26. par.Style = vStyle;
  27. var pic = par.AddRun().AddPicture();
  28. var picBytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "mescius-video-thumbnail.jpg"));
  29. pic.ImageData.SetImage(picBytes, "image/jpeg");
  30. pic.ImageData.WebVideoProperties.SetUrl("https://www.youtube.com/watch?v=RRTCt2TTOyU", "How to Build a Simple Balance Sheet using C# .NET Excel APIs", 400, 400);
  31. pic.Size.Width.Value = 400;
  32. pic.Size.Height.Value = 400;
  33. //
  34. doc.Body.AddParagraph("The End.");
  35. // Done:
  36. return doc;
  37. }
  38. }
  39. }
  40.