使用批注
你可以在PDF文章中添加批注,以记录反馈、评论或标记文档中的任何编辑。
AddNote方法用于添加批注,语法为:
AddNode(node, rect)
AddNode(node, page, rect)
参数 | 说明 |
node | 要添加的批注 |
rect | 被批注的区域,RectangleF 的类型 |
page | 批注区域所在页面,默认为当前页面 |
批注有多种类型,最常用的是PdfSquareNote,下面的代码演示了所有的批注类型:
示例
Dim
file
As
String
=
"c:\temp\test.pdf"
Dim
pdc
As
New
PDFCreator()
pdc.ConformanceLevel = PDF.PdfAConformanceLevel.PdfA1a
Dim
fnt
As
New
Font("宋体",
12)
Dim
rect
As
RectangleF = pdc.PageRectangle()
Dim
rectNode
As
RectangleF
rect.Inflate( - 72, - 72)
Dim
sz
As
SizeF = pdc.MeasureString("Hello
Foxtable",
fnt)
rect.Width = sz.Width
rect.Height = sz.Height
rectNode = rect
rectNode.Inflate(5, 5)
'第一条矩形批注
Dim
note
As
PDF.PdfNoteBase
note =
New
PDF.PdfSquareNote()
'创建矩形批注
note.Contents =
"默认矩形批注"
'批注内容
pdc.AddNote(note, rectNode)
'添加批注
pdc.DrawString("Hello
Foxtable",
fnt, color.Black, rect)
rect.Offset(0, 55)
rectNode.Offset(0, 55)
'第二条矩形批注
note =
New
PDF.PdfSquareNote()
'创建矩形批注
note.ForeColor = Color.Blue
'批注边框改为蓝色
note.Contents =
"蓝框矩形批注"
'批注内容
pdc.AddNote(note, rectNode)
'添加批注
pdc.DrawString("Hello
Foxtable",
fnt, color.Black, rect)
rect.Offset(0, 55)
rectNode.Offset(0, 55)
'第三条椭圆批注
note =
New
PDF.PdfCircleNote()
'创建椭圆批注
note.Contents =
"椭圆批注"
'批注内容
pdc.AddNote(note, rectNode)
'添加批注
pdc.DrawString("Hello
Foxtable",
fnt, color.Black, rect)
rect.Offset(0, 55)
rectNode.Offset(0, 55)
'第四条线性批注,定义线性批注的时候,需要两个PointF参数,分别用于指定起点和终点。
note =
New
PDF.PdfLineNote(New
PointF(rect.Left, rect.Bottom),
New
PointF(rect.Right, rect.Bottom))
note.ForeColor = Color.Blue
'改为蓝色线条
note.Contents =
"线性批注"
'批注内容
pdc.AddNote(note, rectNode)
'添加批注
pdc.DrawString("Hello
Foxtable",
fnt, color.Black, rect)
rect.Offset(0, 55)
rectNode.Offset(0, 55)
'第五条文本框批注
rectNode.Width = rectNode.Width + 60
'设置批注框宽度
Dim
textNote
As
New
PDF.PdfTextNote()
'创建文本批注框
textNote.Contents =
"文本框批注"
'批注内容
textNote.BorderColor = Color.Red
'边框颜色
textNote.ForeColor = Color.Blue
'字体颜色
textNote.FillColor = Color.Beige
'背景颜色
textNote.Font =
New
Font("宋体",
10)
'设置文本框字体
pdc.AddNote(textNote,
rectNode) '添加批注
pdc.Save(file)
Process.Start(file)
生成的文档会显示批注:
提示:
Foxtable内置的PDF文件浏览器不支持批注,请使用第三方PDF浏览原件,例如Acrobat Reader 和 WPS,才能正常显示、编辑和回复批注。