DocAttachments.vb
''
'' This code is part of GrapeCity Documents for PDF samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports System.Text
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf

'' Shows how to attach files to a PDF document.
'' See also the FileAttachments sample that demonstrates file attachment annotations,
'' which are attached to a specific location on a page.
Public Class DocAttachments
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim files As String() =
            {
                "tudor.jpg",
                "sea.jpg",
                "puffins.jpg",
                "lavender.jpg",
                "skye.jpg",
                "fiord.jpg",
                "out.jpg"
            }
        Dim sb = New StringBuilder()
        For Each fn In files
            sb.AppendLine(fn)
        Next
        Util.AddNote(
            "Several images from the sample's Resources/Images folder are attached to this document:" + vbLf + vbLf +
            sb.ToString(), page)
        For Each fn In files
            Dim file = Path.Combine("Resources", "Images", fn)
            Dim fspec = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file))
            doc.EmbeddedFiles.Add(file, fspec)
        Next
        ''
        '' Done:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class