'' 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, 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
            "Several images and PDFs are attached to this document:" + 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)
        '' Done:
        Return doc.Pages.Count
    End Function
End Class