AnnotationTypes.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
'' 演示如何向 PDF 文档添加注释。
Public Class AnnotationTypes
Function CreatePDF(ByVal stream As Stream) As Integer
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
'' 注释作者的用户名:
Dim user1 = "杰米·史密斯"
Dim user2 = "简·多纳休"
Dim tf = New TextFormat() With {.Font = StandardFonts.Helvetica, .FontSize = 10}
Dim noteWidth = 72 * 4
Dim gap = 8
Dim rc = Util.AddNote(
"此示例演示了可以使用 GcDocs.PDF 创建的某些类型的注释。" + vbLf +
"请注意,某些注释类型可能不会在某些查看器(例如内置浏览器查看器)中显示。" +
"要查看此页面上的所有注释,请在 Acrobat Reader 或其他功能齐全的 PDF 查看器中打开它。" +
"",
page)
'' 文字注释:
Dim ip = New PointF(rc.X, rc.Bottom + gap)
rc = Util.AddNote(
"红色文本注释位于此注释的右侧。",
page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
Dim textAnnot = New TextAnnotation() With {
.UserName = user1,
.Contents = "这是注释 1,红色的。",
.Rect = New RectangleF(rc.Right, rc.Top, 72 * 2, 72),
.Color = Color.Red
}
page.Annotations.Add(textAnnot)
'' 对之前注释的回复:
Dim textAnnotReply = New TextAnnotation() With {
.UserName = user2,
.Contents = "这是对第一个注释的回复。",
.Rect = New RectangleF(rc.Right, rc.Top, 72 * 2, 72),
.ReferenceAnnotation = textAnnot,
.ReferenceType = AnnotationReferenceType.Reply
}
page.Annotations.Add(textAnnotReply)
'' 最初打开的文本注释:
ip = New PointF(rc.X, rc.Bottom + gap)
rc = Util.AddNote(
"最初打开的绿色文本注释放置在该注释的右侧。",
page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
Dim textAnnotOpen = New TextAnnotation() With {
.Open = True,
.UserName = user1,
.Contents = "这是最初打开的注释(绿色)。",
.Rect = New RectangleF(rc.Right, rc.Top, 72 * 2, 72),
.Color = Color.Green
}
page.Annotations.Add(textAnnotOpen)
'' 自由文本注释(直接显示在页面上):
ip = New PointF(rc.X, rc.Bottom + gap)
rc = Util.AddNote(
"蓝色自由文本注释位于右侧下方,并带有从该注释到此注释的标注。",
page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
Dim freeAnnot = New FreeTextAnnotation() With {
.Rect = New RectangleF(rc.Right + 18, rc.Bottom + 9, 72 * 2, 72),
.CalloutLine = {
New PointF(rc.Left + rc.Width / 2, rc.Bottom),
New PointF(rc.Left + rc.Width / 2, rc.Bottom + 9 + 36),
New PointF(rc.Right + 18, rc.Bottom + 9 + 36)
},
.LineWidth = 1,
.LineEndStyle = LineEndingStyle.OpenArrow,
.LineDashPattern = New Single() {8, 4},
.Contents = "这是一个自由文本注释,带有指向左侧注释的标注线。",
.Color = Color.LightSkyBlue
}
page.Annotations.Add(freeAnnot)
'' 另一个自由文本注释,里面有一些富文本:
ip = New PointF(rc.X, freeAnnot.Rect.Bottom + gap)
Dim freeRichAnnot = New FreeTextAnnotation() With {
.Rect = New RectangleF(ip.X - 144, ip.Y, 72 * 5, 72),
.LineWidth = 1,
.Color = Color.LightSalmon,
.RichText =
"<body><p>这是另一个<i>自由文本注释</i>,包含<b><i>富文本</i></b>内容。</p></body>"
}
page.Annotations.Add(freeRichAnnot)
'' 注释周围的方形注释:
ip = New PointF(rc.X, freeRichAnnot.Rect.Bottom + gap * 2)
rc = Util.AddNote(
"在该注释周围用 3 磅宽的橙色线绘制的方形注释具有与其关联的丰富文本。",
page, New RectangleF(ip.X, ip.Y, noteWidth, 100))
rc.Inflate(8, 8)
Dim squareAnnot = New SquareAnnotation() With {
.UserName = user2,
.Rect = rc,
.LineWidth = 3,
.Color = Color.Orange,
.RichText =
"<body><p>此<b><i>富文本</i></b>与文本注释周围的方形注释相关联。</p></body>"
}
page.Annotations.Add(squareAnnot)
''
'' 完毕:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class