Skip to content

2.14 Play Sound Files

OgreTransporter edited this page Mar 2, 2020 · 1 revision

The PdfFileWriter supports embedding sound files in the PDF document. Full example of playing sound file is given in the page 7 of OtherExample.cs. Embedding sound files is essentially the same as video files. The only obvious difference is that there is nothing to display.

// create embedded media file
PdfDisplayMedia DisplayMedia = new PdfDisplayMedia(PdfEmbeddedFile.CreateEmbeddedFile(Document, "Ring01.wav"));
DisplayMedia.SetMediaWindow(MediaWindow.Hidden);
AnnotDisplayMedia RingSound = new AnnotDisplayMedia(DisplayMedia);

// display text area to activate the sound
Double LineSpacing = ArialNormal.LineSpacing(12.0);
Double TextPosX = PosX + 0.5 * AreaWidth;
Double TextPosY = PosY + 0.5 * AreaHeight + LineSpacing;
Contents.DrawTextWithAnnotation(Page, ArialNormal, 12.0, TextPosX, TextPosY, TextJustify.Center,
  DrawStyle.Normal, Color.Red, "Click this text to play", RingSound);
TextPosY -= LineSpacing;
Contents.DrawTextWithAnnotation(Page, ArialNormal, 12.0, TextPosX, TextPosY, TextJustify.Center,
  DrawStyle.Normal, Color.Red, "Ringing sound", RingSound);
Clone this wiki locally