//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Text;usingGrapeCity.Documents.Pdf; namespaceDsPdfWeb.Demos.Basics{// Shows how to attach files to a PDF document.// In this sample we attach a few photos and two PDFs, including an AcroForm. // See also the FileAttachments sample that demonstrates file attachment annotations,// which are files associated with a specific location on a page.publicclassDocAttachments {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage();var files = new (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" ) };var sb = newStringBuilder();foreach (var f in files) sb.AppendLine(f.Item2);Common.Util.AddNote("Several images and PDFs are attached to this document:\n\n" + sb.ToString(), page);foreach (var f in files) {var file = Path.Combine("Resources", f.Item1, f.Item2);var fspec = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file)); doc.EmbeddedFiles.Add(file, fspec); }// Done: doc.Save(stream);return doc.Pages.Count; } }}