[]
RichMedia annotation is a reference to the media resources (audio and video) embedded in a PDF document. It will appear as a rectangular box with a play button inside. To add RichMedia annotations to the PDF document, GcPdf provides SetVideo, SetAudio, and SetContent methods of RichMediaAnnotation class.
GcPdf also provides helper classes RichMediaAnnotationActivation, RichMediaAnnotationDeactivation, and RichMediaAnnotationPresentationStyle with constants that define the properties of RichMediaAnnotation class.
RichMediaAnnotation class provides the following properties to set various options for the rich media annotation:
Property | Description |
---|---|
ActivationCondition | Sets the circumstances under which the annotation shall be activated. |
DeactivationCondition | Sets the circumstances under which the annotation shall be deactivated. |
PresentationStyle | Sets the style of presentation of the rich media (embedded or windowed). |
ShowNavigationPane | Sets a value indicating the default behavior of a navigation pane user interface element. |
ShowToolbar | Sets the value indicating the default behavior of an interactive toolbar associated with this annotation. |
Rect | Sets the rectangle that defines the location and size of the annotation on a page. The coordinates of the rectangle are relative to the upper left corner of the page's media box, with the Y (vertical) coordinates increasing from top to bottom. |
Refer to the following example code to add a video using RichMediaAnnotation:
// Initialize GcPdfDocument.
var doc = new GcPdfDocument();
// Add a blank page to the PDF document.
var page = doc.NewPage();
// Initialize GcPdfGraphics.
var g = page.Graphics;
// Provide video path.
var videoPath = Path.Combine("waterfall.mp4");
const int smallGap = 18;
// Set text format.
var tf = new TextFormat()
{
Font = StandardFonts.HelveticaBold,
FontSize = 14
};
// Add a video that plays when the page becomes visible.
var rc = new RectangleF(new PointF(60, 50), new SizeF(500, 10));
// Draw the introductory string.
g.DrawString("The following video plays automatically when the page becomes visible:", tf, rc);
// Initialize RichMediaAnnotation and set its properties.
var rma = new RichMediaAnnotation();
var videoEfs = EmbeddedFileStream.FromFile(doc, videoPath);
var videoFileSpec = FileSpecification.FromEmbeddedStream(Path.GetFileName(videoPath), videoEfs);
// Set the media for the video.
rma.SetVideo(videoFileSpec);
// Set presentation style.
rma.PresentationStyle = RichMediaAnnotationPresentationStyle.Embedded;
// Set activation condition.
rma.ActivationCondition = RichMediaAnnotationActivation.PageBecomesVisible;
// Set deactivation condition.
rma.DeactivationCondition = RichMediaAnnotationDeactivation.PageBecomesInvisible;
// Set behavior of navigation pane.
rma.ShowNavigationPane = true;
// Set page to which RichMediaAnnotation will be added.
rma.Page = page;
// Set rectangle in which RichMediaAnnotation will be added.
rma.Rect = new RectangleF(rc.X, rc.Bottom + smallGap, 72 * 5, 72 * 5 * 0.56f);
// Save the document.
doc.Save("RichMediaAnnotation.pdf");