PDF 문서에 첨부파일 추가하기

Contents
[ ]

첨부파일은 다양한 정보와 다양한 파일 유형을 포함할 수 있습니다. 이 문서에서는 PDF 파일에 첨부파일을 추가하는 방법을 설명합니다.

다음 코드 스니펫은 Aspose.Drawing 라이브러리와 함께 작동합니다.

  1. 새 C# 프로젝트를 만듭니다.
  2. Aspose.PDF DLL에 대한 참조를 추가합니다.
  3. Document 객체를 생성합니다.
  4. 추가할 파일과 파일 설명으로 FileSpecification 객체를 생성합니다.
  5. FileSpecification 객체를 Document 객체의 EmbeddedFiles 컬렉션에 추가합니다. 컬렉션의 Add 메서드를 사용합니다.

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");
    }
}