使用TextBox
添加TextBox的参考代码如下,可在命令窗口测试执行:
Dim
file
As
String
=
"c:\temp\test.pdf"
Dim
fnt
As
New
Font("微软雅黑",
12)
Dim
pdc
As
New
PDFCreator()
Dim
rectPage
As
RectangleF = pdc.PageRectangle
Dim
rect
As
RectangleF = rectPage
rect.Inflate( - 72, - 72)
'用于添加TextBox的Lambda过程,tOffSet为文本框和标题的水平距离,tWidth为文本框宽度,tDefaultText为默认值,tRows为行高倍数
Dim
CreateTextBox =
Sub(tCaption
As
String,
tFont
As
Font, tRect
As
RectangleF, tOffSet
As
Double,
tWidth
As
Double,
tDefaultText
As
String,
tRows
As
Integer)
pdc.DrawString(tCaption &
":",
tFont, color.Black, tRect)
Dim
tRectBox
As
New
RectangleF(tRect.Left + tOffSet, tRect.Top - 2, tWidth, tFont.Size * tRows + 4)
Dim
tTextBox
As
New
PDF.PdfTextBox()
tTextBox.Font = tFont
tTextBox.BorderColor = Color.Azure
tTextBox.BorderWidth = PDF.FieldBorderWidth.Medium
tTextBox.DefaultText = tDefaultText
If
tRows > 1
Then
tTextBox.IsMultiline =
True
tTextBox.Alignment = StringAlignment.Near
End
If
pdc.AddField(tTextBox, tRectBox)
End
Sub
CreateTextBox.Invoke("姓名",
fnt, rect, 40, 160,
"张三",
1)
rect.Offset(0, 25)
CreateTextBox.Invoke("部门",
fnt, rect, 40, 160,
"销售部",
1)
rect.Offset(0, 25)
CreateTextBox.Invoke("年龄",
fnt, rect, 40, 160,
"50",
1)
rect.Offset(0, 25)
CreateTextBox.Invoke("备注",
fnt, rect, 40, 160,
"请输入备注",
4)
pdc.Save(file)
Process.Start(file)
生成的文档如下: