'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.LinqImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.Annotations '' This demo shows how to replace an image in a PDF with a video clip.PublicClassInsertVideoPublicFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim pdfPath = Path.Combine("Resources", "PDFs", "Wetlands.pdf")Dim videoPath = Path.Combine("Resources", "Video", "waterfall.mp4") Using fs = File.OpenRead(pdfPath)Dim doc = NewGcPdfDocument() doc.Load(fs)Dim page = doc.Pages.First() ' Find the largest image on the first page:Dim imageRect AsRectangleF = RectangleF.EmptyForEach img In page.GetImages()ForEach l In img.Locations.Where(Function(l_) l_.Page.Index = 0)Dim r = l.PageBounds.ToRect()If r.Height > imageRect.HeightThen imageRect = rEndIfNextNextIf imageRect = RectangleF.EmptyThenThrowNew Exception("Could not find an image on the first page.")EndIf ' Remove it: doc.Redact(NewRedactAnnotation() With {.Page = page, .Rect = imageRect}) ' Add a video clip in the rectangle previously occupied by the image:Dim rma = NewRichMediaAnnotation()Dim videoEfs = EmbeddedFileStream.FromFile(doc, videoPath)Dim 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.CountEndUsingEndFunctionEndClass