// 完毕:
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Pdf.Annotations;
namespace DsPdfWeb.Demos.Basics
{
// 此示例演示如何向 PDF 文档添加声音注释。
public class SoundAnnotations
{
public int CreatePDF(Stream stream)
{
var doc = new GcPdfDocument();
var page = doc.NewPage();
// 注释作者的用户名:
var user1 = "丁艾夫";
var user2 = "瓦东";
var tf = new TextFormat() { Font = StandardFonts.Helvetica, FontSize = 10 };
var noteWidth = 72 * 3;
var gap = 8;
var rc = Common.Util.AddNote(
"此示例演示使用 GcDocs.PDF 添加声音注释。" +
"",
page);
// AIFF声音注释:
var ip = new PointF(rc.X, rc.Bottom + gap);
rc = Common.Util.AddNote("红色声音注释放置在该音符的右侧。",
page, new RectangleF(ip.X, ip.Y, noteWidth, 100));
var aiffAnnot = new SoundAnnotation()
{
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 = Common.Util.AddNote("蓝色声音注释放置在该音符的右侧。",
page, new RectangleF(ip.X, ip.Y, noteWidth, 100));
var wavAnnot = new SoundAnnotation()
{
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);
return doc.Pages.Count;
}
}
}