DocAttachments.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Text
  7. Imports GrapeCity.Documents.Text
  8. Imports GrapeCity.Documents.Pdf
  9.  
  10. '' Shows how to attach files to a PDF document.
  11. '' See also the FileAttachments sample that demonstrates file attachment annotations,
  12. '' which are attached to a specific location on a page.
  13. Public Class DocAttachments
  14. Function CreatePDF(ByVal stream As Stream) As Integer
  15. Dim doc = New GcPdfDocument()
  16. Dim page = doc.NewPage()
  17. Dim files As (String, String)() =
  18. {
  19. ("Images", "tudor.jpg"),
  20. ("Images", "sea.jpg"),
  21. ("Images", "puffins.jpg"),
  22. ("Images", "lavender.jpg"),
  23. ("Images", "skye.jpg"),
  24. ("Images", "fiord.jpg"),
  25. ("Images", "newfoundland.jpg"),
  26. ("PDFs", "HelloWorld.pdf"),
  27. ("PDFs", "FormFields.pdf")
  28. }
  29. Dim sb = New StringBuilder()
  30. For Each f In files
  31. sb.AppendLine(f.Item2)
  32. Next
  33. Util.AddNote(
  34. "Several images and PDFs are attached to this document:" + vbLf + vbLf +
  35. sb.ToString(), page)
  36. For Each f In files
  37. Dim file = Path.Combine("Resources", f.Item1, f.Item2)
  38. Dim fspec = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file))
  39. doc.EmbeddedFiles.Add(file, fspec)
  40. Next
  41. ''
  42. '' Done:
  43. doc.Save(stream)
  44. Return doc.Pages.Count
  45. End Function
  46. End Class
  47.