SoundAnnotations.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9. Imports GrapeCity.Documents.Pdf.Annotations
  10.  
  11. '' This sample shows how to add sound annotations to a PDF document.
  12. Public Class SoundAnnotations
  13. Sub CreatePDF(ByVal stream As Stream)
  14. Dim doc = New GcPdfDocument()
  15. Dim page = doc.NewPage()
  16. Dim g = page.Graphics
  17. '' User names for annotations' authors:
  18. Dim user1 = "Aiff Ding"
  19. Dim user2 = "Wav Dong"
  20.  
  21. Dim tf = New TextFormat() With {.Font = StandardFonts.Helvetica, .FontSize = 10}
  22. Dim noteWidth = 72 * 3
  23. Dim gap = 8
  24.  
  25. Dim rc = Util.AddNote(
  26. "This sample demonstrates adding sound annotations using DsPdf. " +
  27. "The track associated with an annotation can be played in a viewer that supports it. " +
  28. "PDF supports AIFF and WAV tracks in sound annotations.",
  29. page)
  30.  
  31. '' AIFF sound annotation:
  32. Dim ip = New PointF(rc.X, rc.Bottom + gap)
  33. rc = Util.AddNote("A red sound annotation is placed to the right of this note. Double click the icon to play the sound.",
  34. page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
  35. Dim aiffAnnot = New SoundAnnotation() With
  36. {
  37. .UserName = user1,
  38. .Contents = "Sound annotation with an AIFF track.",
  39. .Rect = New RectangleF(rc.Right, rc.Top, 24, 24),
  40. .Icon = SoundAnnotationIcon.Speaker,
  41. .Color = Color.Red,
  42. .Sound = SoundObject.FromFile(Path.Combine("Resources", "Sounds", "ding.aiff"), AudioFormat.Aiff)
  43. }
  44. page.Annotations.Add(aiffAnnot)
  45.  
  46. '' WAV sound annotation:
  47. ip = New PointF(rc.X, rc.Bottom + gap)
  48. rc = Util.AddNote("A blue sound annotation is placed to the right of this note. Double click the icon to play the sound.",
  49. page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
  50. Dim wavAnnot = New SoundAnnotation() With
  51. {
  52. .UserName = user2,
  53. .Contents = "Sound annotation with a WAV track.",
  54. .Rect = New RectangleF(rc.Right, rc.Top, 24, 24),
  55. .Icon = SoundAnnotationIcon.Mic,
  56. .Color = Color.Blue,
  57. .Sound = SoundObject.FromFile(Path.Combine("Resources", "Sounds", "dong.wav"), AudioFormat.Wav)
  58. }
  59. page.Annotations.Add(wavAnnot)
  60.  
  61. '' Done:
  62. doc.Save(stream)
  63. End Sub
  64. End Class
  65.