# RichMedia Annotation

DsPdf is a Document Solutions product that offers a rich library to read, create, modify, and save PDF files without using any external tool.

## Content

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, DsPdf provides [SetVideo](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotation.SetVideo.html), [SetAudio](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotation.SetAudio.html), and [SetContent](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotation.SetContent.html) methods of [RichMediaAnnotation](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotation.html) class.
DsPdf also provides helper classes [RichMediaAnnotationActivation](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotationActivation.html), [RichMediaAnnotationDeactivation](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotationDeactivation.html), and [RichMediaAnnotationPresentationStyle](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotationPresentationStyle.html) with constants that define the properties of RichMediaAnnotation class.
![](https://cdn.mescius.io/document-site-files/images/884d2bfb-301b-49bc-8d90-656c5b910507/images/rich-media-annotation-dspdf.gif)
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:

```csharp
// 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");
```

User can also fetch the media from the RichMedia annotation using [GetContent](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.RichMediaAnnotation.GetContent.html) method of RichMediaAnnotation class.