Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Attachments can contain a wide variety of information and can be of a variety of file types. This article explains how to add an attachment to a PDF file.
The next code snippet also works with Aspose.Drawing library.
The EmbeddedFiles collection contains all the attachments in the PDF file. The following code snippet shows you how to add an attachment in a PDF document.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddEmbeddedFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "AddAttachment.pdf"))
{
// Setup new file to be added as attachment
Aspose.Pdf.FileSpecification fileSpecification = new Aspose.Pdf.FileSpecification(dataDir + "test.txt", "Sample text file");
// Add attachment to document's attachment collection
document.EmbeddedFiles.Add(fileSpecification);
// Save PDF document
document.Save(dataDir + "AddAnnotations_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.