SoundAnnotations.vb
''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf.Annotations

'' This sample shows how to add sound annotations to a PDF document.
Public Class SoundAnnotations
    Sub CreatePDF(ByVal stream As Stream)
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim g = page.Graphics
        '' User names for annotations' authors:
        Dim user1 = "Aiff Ding"
        Dim user2 = "Wav Dong"

        Dim tf = New TextFormat() With {.Font = StandardFonts.Helvetica, .FontSize = 10}
        Dim noteWidth = 72 * 3
        Dim gap = 8

        Dim rc = Util.AddNote(
            "This sample demonstrates adding sound annotations using DsPdf. " +
            "The track associated with an annotation can be played in a viewer that supports it. " +
            "PDF supports AIFF and WAV tracks in sound annotations.",
            page)

        '' AIFF sound annotation:
        Dim ip = New PointF(rc.X, rc.Bottom + gap)
        rc = Util.AddNote("A red sound annotation is placed to the right of this note. Double click the icon to play the sound.",
            page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
        Dim aiffAnnot = New SoundAnnotation() With
        {
            .UserName = user1,
            .Contents = "Sound annotation with an AIFF track.",
            .Rect = New RectangleF(rc.Right, rc.Top, 24, 24),
            .Icon = SoundAnnotationIcon.Speaker,
            .Color = Color.Red,
            .Sound = SoundObject.FromFile(Path.Combine("Resources", "Sounds", "ding.aiff"), AudioFormat.Aiff)
        }
        page.Annotations.Add(aiffAnnot)

        '' WAV sound annotation:
        ip = New PointF(rc.X, rc.Bottom + gap)
        rc = Util.AddNote("A blue sound annotation is placed to the right of this note. Double click the icon to play the sound.",
            page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
        Dim wavAnnot = New SoundAnnotation() With
        {
            .UserName = user2,
            .Contents = "Sound annotation with a WAV track.",
            .Rect = New RectangleF(rc.Right, rc.Top, 24, 24),
            .Icon = SoundAnnotationIcon.Mic,
            .Color = Color.Blue,
            .Sound = SoundObject.FromFile(Path.Combine("Resources", "Sounds", "dong.wav"), AudioFormat.Wav)
        }
        page.Annotations.Add(wavAnnot)

        '' Done:
        doc.Save(stream)
    End Sub
End Class