Add/Attach files to an existing PDF file in C# using Aspose.PDF for .NET

Dear all, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I would like to add some attachments to an existing pdf file. How can I achieve this b< using Aspose.PDF. I read the tutorial where the general attachment process is described. But how can I open an existing pdf file.

Thanks in Advance

Erik

Hi Erik,

You can use Aspose.PDF for .NET to add attachments without annotation. You can also use FileAttachmentAnnotation to add attachment and create annotation to open the file. You can create a link to an external PDF file as well using LinkAnnotation; this method opens a specific page of an external PDF. You can also find the examples on the specified links.

I hope this helps. If you have any further questions or concerns, please do let us know.
Regards,

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your reply. I basically know how to add file attachments. But I’m not quite sure how I should perform this task if I don’t create a new pdf file from scratch. Can you provide me just a little piece of code demonstration how to open an existing pdf file, attach some files and finally save the modified file?

In Adobe.Acrobat the result should look like the provided attachment.

Thanks in advance

Erik

Hi Erik,

You can use the following code snippet to open an existing PDF file, add attachments and then save the output file:


//add new file attachments

Aspose.Pdf.Kit.PdfContentEditor editor = new Aspose.Pdf.Kit.PdfContentEditor();

//bind input PDF file

editor.BindPdf(“input.pdf”);

//add attachments

editor.AddDocumentAttachment(“File1.txt”, “File1”);

editor.AddDocumentAttachment(“File2.txt”, “File2”);

editor.AddDocumentAttachment(“File3.txt”, “File3”);

//save output PDF file

editor.Save(“output.pdf”);

If you want to remove existing attachments, you can use the following code:

//remove existing file attachments
Aspose.Pdf.Kit.PdfContentEditor editor = new Aspose.Pdf.Kit.PdfContentEditor();
editor.BindPdf("input.pdf");
editor.DeleteAttachments();
editor.Save("output.pdf");


I hope this helps. If you need any further assistance or you think that I have not understood your requirement properly then please do let me know.

Regards,

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

the code snippet is exactly what I was looking for. If I use it to attach my additional files to the main report, the files size explodes from 1,5 MB up to > 11MB (the size of all attached files together is lesser than 5 MB). If I do the same thing in Adobe Acrobat, the size of the original file grows only by 500 KB. Unfortunately I can’t provide you my sample files because they contain highly confidential information.

Any idea???

Thanks in Advance

Erik

Hi Erik,

I can understand your concern. I would like to share with you that any documents shared with the Aspose staff are kept confidential and used for testing purposes. You can mark the post as private and attach the sample documents, so that the documents are accessible by Aspose staff only.

Nevertheless, if you still don’t feel like sharing the documents, can you please share the following information with us so we could reproduce the issue at our end?

1. The size of the original PDF document
2. The number of the files attached to the document
3. The type of the files being attached
4. Size of the individual files to be attached

We’ll try to test the issue at our end and update you accordingly.

We’re sorry for the inconvenience.
Regards,

<o:p></o:p>

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I will try to create some dummy files tomorrow. I’m fully aware that you will keep our information confidential, but I can’t provide the original files to you. Right now I can just answer the second and the third question. I have to attach .xls files. The number of documents varies between one and five. The size of these files and the size of the main report depend on the specific content of each document.

Erik

Hi Erik<o:p>,

Thank you for sharing the detailed information. We’ll try to reproduce the issue at our end update you with the test results the earliest possible.

We’re looking forward to help you out.
Regards,

</o:p>

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

just one more piece of information. I’m using Aspose.Cells to save an xls file in pdf format. This file is then the input file for the attachment process which results in a large pdf file. If I create the basic pdf file with Adobe.Acrobat instead and perform the same attachment process with Aspose.PDF.Kit, the resulting file has the expected files size.

I’m still working on the example files to clarify the issue.

Regards

Erik

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please find attached all needed files to reproduce the issue.

Example.xls : basic xls file of the report

reportAspose.xls : final report in xls format

reportAspose.pdf : final report in pdf format without attachments (created with Aspose.cells)

reportAdobe.pdf : final report in pdf format without attachments (created with Adobe Acrobat)

AsposeAttachment : final report with attachments (created with Aspose.Pdf.Kit)

AdobeAttachement : final report with attachments (created with Adobe Acrobat)

XXXX*.xls : required attachments

Code.txt : sample source code

If I use the reportAspose.pdf file as starting point for the attachment process, the whole process is really time consuming. If I use the adobe file instead, the process is executed within a few seconds.

If youe need further information, please let me know.

Erik

Hi Erik,

Thank you very much for your cooperation in helping us reproduce this issue. I have logged this issue as PDFKITNET-14401in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once the issue is resolved.

We’re sorry for the inconvenience.
Regards,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Hi,

did you made any progress to fix this issue? When can I expect a solution?

Thanks and best regards

Erik

Hi Erik,

Our team is looking into this issue, however I’m afraid, I can’t share the ETA at the moment. Please spare us some time so we could get a better understanding of the issue. We’ll update you with the ETA the earliest possible.

We’re sorry for the inconvenience and appreciate your patience.
Regards,

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Can you give me today an ETA of this feature? It is the last one that we need to completely automate our reporting system. I have to report this date to my chief.

Thanks in advance

Erik

Hi Erik,

I have asked our team to share the ETA of this issue. You’ll be updated as some response is received.

We’re sorry for the inconvenience and appreciate your patience.
Regards,

Hi Erik,

I would like to inform you that, as far as the output file size is concerned, we’ll provide you the resolution in our monthly release due at the end of April; however, we’ll try to provide you a hotfix in the mid of April.

Regarding the time difference between the two files (reportAspose.pdf vs. reportAdobe.pdf), I would like to share that the reportAspose.pdf contains more objects than the reportAdobe.pdf that’s why it is quite natural to take different time to process both of these files. I have contacted Aspose.Cells team to look further into this difference and you’ll be updated accordingly.

If you have any further questions, please do let us know.
Regards,

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

it is May. When can I expect the mentioned fix / release?

Thanks & Regards

Erik

Hi Erik,

This issue is resolved in our upcoming monthly release, which will be published in a couple of days. You’ll be notified via this forum thread.

If you have any further questions, please do let us know.
Regards,


The issues you have found earlier (filed as 14401) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry. I can’t agree that the mentioned issue is fixed. It takes more then 8 minutes to attach 6 excel files. After attaching the files the file size explodes from 3 up to 30 MB. Under these circumstances I can’t use this feature (but I’m in desperate need of it)

Regards

Erik