SoundAnnotations.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf.Annotations
'' 此示例演示如何向 PDF 文档添加声音注释。
Public Class SoundAnnotations
Sub CreatePDF(ByVal stream As Stream)
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
Dim g = page.Graphics
'' 注释作者的用户名:
Dim user1 = "丁艾夫"
Dim user2 = "瓦东"
Dim tf = New TextFormat() With {.Font = StandardFonts.Helvetica, .FontSize = 10}
Dim noteWidth = 72 * 3
Dim gap = 8
Dim rc = Util.AddNote(
"此示例演示使用 GcDocs.PDF 添加声音注释。" +
"",
page)
'' AIFF声音注释:
Dim ip = New PointF(rc.X, rc.Bottom + gap)
rc = Util.AddNote("红色声音注释放置在该音符的右侧。",
page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
Dim aiffAnnot = New SoundAnnotation() With
{
.UserName = user1,
.Contents = "带有 AIFF 轨道的声音注释。",
.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声音注释:
ip = New PointF(rc.X, rc.Bottom + gap)
rc = Util.AddNote("蓝色声音注释放置在该音符的右侧。",
page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
Dim wavAnnot = New SoundAnnotation() With
{
.UserName = user2,
.Contents = "带 WAV 轨道的声音注释。",
.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)
'' 完毕:
doc.Save(stream)
End Sub
End Class