RichMedia.vb
C# VB
'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.IOImports System.DrawingImports GrapeCity.Documents.PdfImports GrapeCity.Documents.Pdf.Annotations
'' This demo shows how to add video and audio clips to a PDF using RichMediaAnnotation.Public Class RichMedia Public Function CreatePDF(ByVal stream As Stream) As Integer Dim doc = New GcPdfDocument() Dim page = doc.NewPage()
Dim videoPath = Path.Combine("Resources", "Video", "waterfall.mp4") Dim audioPath0 = Path.Combine("Resources", "Sounds", "city-noises.mp3") Dim audioPath1 = Path.Combine("Resources", "Sounds", "dong.wav") Const smallGap As Integer = 18 Const largeGap As Integer = 36
' Add a video which plays when the page becomes visible: Dim rc = Util.AddNote("The following video plays automatically when the page becomes visible:", page) Dim rma = New RichMediaAnnotation() 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 = New RectangleF(rc.X, rc.Bottom + smallGap, 72 * 5, 72 * 5 * 0.56F)
' Add the same video clip which plays in a popup window (reuse the FileSpecification): rc = Util.AddNote("The same video that plays in a popup window:", page, New RectangleF(rc.X, rma.Rect.Bottom + largeGap, rc.Width, 0)) rma = New RichMediaAnnotation() rma.SetVideo(videoFileSpec) rma.PresentationStyle = RichMediaAnnotationPresentationStyle.Windowed rma.ActivationCondition = RichMediaAnnotationActivation.UserAction rma.Page = page rma.Rect = New RectangleF(rc.X, rc.Bottom + smallGap, 144, 144)
' Add a couple of audio clips: rc = Util.AddNote("Two audio clips that play when clicked:", page, New RectangleF(rc.X, rma.Rect.Bottom + largeGap, rc.Width, 0)) rma = New RichMediaAnnotation() Dim audioEfs0 = EmbeddedFileStream.FromFile(doc, audioPath0) Dim audioFileSpec0 = FileSpecification.FromEmbeddedStream(Path.GetFileName(audioPath0), audioEfs0) rma.SetAudio(audioFileSpec0) rma.PresentationStyle = RichMediaAnnotationPresentationStyle.Embedded rma.ActivationCondition = RichMediaAnnotationActivation.UserAction rma.Page = page rma.Rect = New RectangleF(rc.X, rc.Bottom + smallGap, 72, 36) ' rma = New RichMediaAnnotation() Dim audioEfs1 = EmbeddedFileStream.FromFile(doc, audioPath1) Dim audioFileSpec1 = FileSpecification.FromEmbeddedStream(Path.GetFileName(audioPath1), audioEfs1) rma.SetAudio(audioFileSpec1) rma.PresentationStyle = RichMediaAnnotationPresentationStyle.Embedded rma.ActivationCondition = RichMediaAnnotationActivation.UserAction rma.Page = page rma.Rect = New RectangleF(rc.X + 144, rc.Bottom + smallGap, 72, 36)
'' Done: doc.Save(stream) Return doc.Pages.Count End FunctionEnd Class