文檔金喜正規買球>>Aspose.PDF使用教程>>Aspose.Pdf使用教程:在PDF文件中添加附件
Aspose.Pdf使用教程:在PDF文件中添加附件
要在一個PDF文檔中添加附件,您需要創建一個要添加的FileSpecification對象和文件的描述。之后就可以使用集合的Add方法將之添加到Document對象的EmbeddedFiles集合中。 這個EmbeddedFiles集合包含添加到PDF文件中的所有附件。
下面的代碼片段演示了如何在PDF文件中添加附件:
C#
//open document Document pdfDocument = new Document("input.pdf"); //setup new file to be added as attachment FileSpecification fileSpecification = new FileSpecification("test.txt", "Sample text file"); //add attachment to document's attachment collection pdfDocument.EmbeddedFiles.Add(fileSpecification); //save new output pdfDocument.Save("output.pdf");
VB.NET
'open document Dim pdfDocument As New Document("input.pdf") 'setup new file to be added as attachment Dim fileSpecification As New FileSpecification("test.txt", "Sample text file") 'add attachment to document's attachment collection pdfDocument.EmbeddedFiles.Add(fileSpecification) 'save new output pdfDocument.Save("output.pdf")