//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Annotations;usingSystem.Linq; namespaceDsPdfWeb.Demos.Basics{// This demo shows how to replace an image in a PDF with a video clip.publicclassInsertVideo {publicintCreatePDF(Stream stream) {var pdfPath = Path.Combine("Resources", "PDFs", "Wetlands.pdf");var videoPath = Path.Combine("Resources", "Video", "waterfall.mp4"); usingvar fs = File.OpenRead(pdfPath);var doc = newGcPdfDocument(); doc.Load(fs);var page = doc.Pages.First(); // Find the largest image on the first page:RectangleF imageRect = RectangleF.Empty;foreach (var img in page.GetImages()) {foreach (var l in img.Locations.Where(l_ => l_.Page.Index == 0)) {var r = l.PageBounds.ToRect();if (r.Height > imageRect.Height) imageRect = r; } }if (imageRect == RectangleF.Empty)thrownewException("Could not find an image on the first page."); // Remove it: doc.Redact(newRedactAnnotation() { Page = page, Rect = imageRect }); // Add a video clip in the rectangle previously occupied by the image:var rma = newRichMediaAnnotation();var videoEfs = EmbeddedFileStream.FromFile(doc, videoPath);var videoFileSpec = FileSpecification.FromEmbeddedStream(Path.GetFileName(videoPath), videoEfs); rma.SetVideo(videoFileSpec); rma.PresentationStyle = RichMediaAnnotationPresentationStyle.Embedded; rma.ActivationCondition = RichMediaAnnotationActivation.PageBecomesVisible; rma.DeactivationCondition = RichMediaAnnotationDeactivation.PageBecomesInvisible; rma.ShowNavigationPane = true; rma.Page = page; rma.Rect = imageRect; // Done: doc.Save(stream);return doc.Pages.Count; } }}