DocAttachments.vb
'' 完毕:
Imports System.IO
Imports System.Text
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf

'' 演示如何将文件附加到 PDF 文档。
'' 另请参阅演示文件附件注释的FileAttachments示例,
'' 它们附加到页面上的特定位置。
Public Class DocAttachments
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim files As (String, String)() =
            {
                ("Images", "tudor.jpg"),
                ("Images", "sea.jpg"),
                ("Images", "puffins.jpg"),
                ("Images", "lavender.jpg"),
                ("Images", "skye.jpg"),
                ("Images", "fiord.jpg"),
                ("Images", "newfoundland.jpg"),
                ("PDFs", "HelloWorld.pdf"),
                ("PDFs", "FormFields.pdf")
            }
        Dim sb = New StringBuilder()
        For Each f In files
            sb.AppendLine(f.Item2)
        Next
        Util.AddNote(
            "本文档附加了一些图像和 PDF:" + vbLf + vbLf +
            sb.ToString(), page)
        For Each f In files
            Dim file = Path.Combine("Resources", f.Item1, f.Item2)
            Dim fspec = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file))
            doc.EmbeddedFiles.Add(file, fspec)
        Next
        ''
        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class