Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
附件可以包含各种信息,并且可以是多种文件类型。本文解释了如何将附件添加到 PDF 文件。
下一个代码片段也适用于 Aspose.Drawing 库。
EmbeddedFiles 集合包含 PDF 文件中的所有附件。以下代码片段演示了如何在 PDF 文档中添加附件。
// 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.