Attaching documents to existing pdf

I see the following code, and it works. But I am not seeing a good example of how to attach documents to an existing pdf.

 string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Attachments();
        // Open document
        PdfContentEditor contentEditor = new PdfContentEditor();
        contentEditor.BindPdf(dataDir+ "AddAttachment.pdf");

        // Add attachment
        contentEditor.AddDocumentAttachment(dataDir+ "test.txt", "Attachment Description");

        // Save updated PDF
        contentEditor.Save(dataDir+ "AddAttachment_out.pdf");
        // ExEnd:AddAttachment`Preformatted text`

@nightcoder

Can you please explain a bit more like which of your requirements are not being met using this code snippet? We will further proceed to assist you accordingly. You can also check below code example that uses DOM approach to attach files in an existing PDF:

I apologize for not being clear. I have a pdf that has content. I would like to open the pdf so as to attach documents. Using the example code PdfContentEditor is a pdf, but its a new pdf, not an existing one.
So I am not finding an example of loading a pdf using aspose.pdf and then binding (.BindPdf) that function just doesn’t exist after opening the existing document.

If the answer is this line here:
pdfDocument.EmbeddedFiles.Add(fileSpecification);

I am trying this:
var ms = new MemoryStream(l.attachment);
FileSpecification fileSpecification = new FileSpecification(ms, display);
fileSpecification.MIMEType = l.fileExt;
pdf.EmbeddedFiles.Add(fileSpecification);

This works perfectly. Please close this issue. Thanks for all the help.

@nightcoder

It is nice to hear that you were able to sort your issue out. Please keep using our API and feel free to create a new topic in case you need further assistance or face any issues.