'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Pdf.Actions
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
'' 此示例演示如何在页面上创建文件附件注释。
'' 另请参阅演示文档级文件附件的DocAttachments 示例。
Public Class FileAttachments
Function CreatePDF(ByVal stream As Stream) As Integer
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
Dim g = page.Graphics
Dim rc = Util.AddNote(
"示例的 Resources/Images 文件夹中的一些文件已附加到此页。" + vbLf +
"",
page)
Dim ip = New PointF(rc.X, rc.Bottom + 9)
Dim attSize = New SizeF(36, 12)
Dim gap = 8
Dim files As String() = {
"tudor.jpg",
"sea.jpg",
"puffins.jpg",
"lavender.jpg",
"skye.jpg",
"fiord.jpg",
"newfoundland.jpg"
}
For Each fn In files
Dim File = Path.Combine("Resources", "Images", fn)
Dim faa = New FileAttachmentAnnotation() With {
.Color = Color.FromArgb(&HFFC540A5),
.UserName = "杰米·史密斯",
.Rect = New RectangleF(ip.X, ip.Y, attSize.Width, attSize.Height),
.Contents = "附件文件:" + File,
.Icon = FileAttachmentAnnotationIcon.Paperclip,
.File = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, File))
}
page.Annotations.Add(faa)
g.FillRectangle(faa.Rect, Color.FromArgb(&HFF40C5A3))
g.DrawRectangle(faa.Rect, Color.FromArgb(&HFF6040C5))
ip.Y += attSize.Height + gap
Next
''
'' 完毕:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class