''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.AcroForms
Imports GrapeCity.Documents.Pdf.Actions
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Text
Public Class ActionSound1
Public Function CreatePDF(ByVal stream As Stream) As Integer
Dim soundPaths As String() = {
Path.Combine("Resources", "Sounds", "ding.aiff"),
Path.Combine("Resources", "Sounds", "dong.wav")
}
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
Dim rc = Util.AddNote(
"This sample creates a PDF with some pushbuttons, " &
"and associates each button's MouseDown event " &
"with an ActionSound that plays a sound file.",
page)
Dim resolution = page.Graphics.Resolution
Dim g = page.Graphics
Dim tf = New TextFormat() With {.Font = StandardFonts.Times, .FontSize = 14}
' Prep a simple layout:
Dim ip = New PointF(resolution, rc.Bottom + resolution / 2)
Dim fldOffset = resolution * 2.5F
Dim fldHeight = tf.FontSize * 1.2F
Dim dY = resolution * 0.4F
' Add the buttons with ActionSound on MouseDown events:
For Each soundPath In soundPaths
Dim btn = New PushButtonField()
btn.Widget.Page = page
btn.Widget.Rect = New RectangleF(ip.X + fldOffset, ip.Y, resolution, fldHeight)
btn.Widget.ButtonAppearance.Caption = Path.GetFileNameWithoutExtension(soundPath)
Dim sound = New ActionSound(SoundObject.FromFile(soundPath)) With {
.Volume = 0.5F
}
btn.Widget.Events.MouseDown = sound
btn.Widget.Highlighting = HighlightingMode.Invert
doc.AcroForm.Fields.Add(btn)
ip.Y += dY
Next
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class