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

Hi Erik,

Please use the following line before attaching the files:


Settings.SaveMode = SaveMode.Append;


I hope this helps. If you still find the issue, please do let us know.
Regards,

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

Where should I integrate this code snippet? Plesase find my current sourcecode attached. It is possible to use a SaveAs() method???

Erik

Hi Erik,

Please update your code as shown below:



FileInfo[] files = dirInfo.GetFiles();


//add new line over here

Settings.SaveMode = SaveMode.Append;


for (int i = 0; i < files.Length; i++)

{

if (!files[i].FullName.Equals(pdf) && !files[i].FullName.Equals(xls))

{

editor.AddDocumentAttachment(files[i].FullName, “XXX”);

count++;

}

}


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

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

if I change my code according to your suggestion, I get the following error message:

„Aspose does not support Field Flattening in append mode“ if I call editor.save(filename). What’s wrong?

Erik

Hi Erik,

I have notified our development team about this issue; the issue id is PDFKITNET-16605. Our team is looking into this issue and you’ll be updated with a resolution the earliest possible.

We’re sorry for the inconvenience.
Regards,

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

can you please state your ETA for this issue.

Thanks in advance

Erik

Hi Erik,

I would like to share with you that our team is working on this issue, however we’re unable to estimate the time and effort required for this issue at the moment. Nevertheless, we’ll try to provide you the fix in our next monthly release due at the end of June.

We’re sorry for the inconvenience.
Regards,

The issues you have found earlier (filed as 16605) 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" />

after an initial test I found out that Aspose still doesn’t support Field Flattening in append mode. I got the same error message as in version 4.5.

When will you fix this issue?

Erik

Hi Erik,

Please add the following line of code before adding any attachments:


Aspose.Pdf.Kit.Settings.SaveMode = Aspose.Pdf.Kit.SaveMode.Append;


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

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

my code already contains the mentioned line of code. What’s wrong?

Regards

Erik

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

editor.BindPdf(pdf);

Aspose.Pdf.Kit.Settings.SaveMode = Aspose.Pdf.Kit.SaveMode.Append;

int count = 0;

DirectoryInfo dirInfo = new DirectoryInfo(r.TempDirLang);

FileInfo[] files = dirInfo.GetFiles();

for (int i = 0; i < files.Length; i++)

{

if (!files[i].FullName.Equals(pdf) && !files[i].FullName.Equals(xls))

{

editor.AddDocumentAttachment(files[i].FullName, "xxx");

count++;

}

}

if (count > 0)

{

editor.Save(@"c:\test.pdf");

}

Hi Erik,

I have again tested the issue at my end and it is working fine. Can you please make sure that you’re using the latest version (4.6.0) at your end?

Please go through the following steps:

1. Remove any existing reference to Aspose.Pdf.Kit
2. Build the project without adding any reference
3. Add reference to the new 4.6.0 DLL in your project
4. Build the project with the new reference
5. Try to test the project.

If it still doesn’t work then please do let us know.

We’re sorry for the inconvenience.
Regards,

Hi Erik,

Please specify the license file as well. This issue might occur if the license is not specified.

I hope this helps.
Regards,

Hi,

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

This morning I did all mentioned steps. The only thing I forgot was to activate the license file (Aspose.Total). After activating the license I still get the error message.

But there is another funny thing. Aspose generates the final output file with all attachments also when my code throws an exception.

But maybe this is a problem with my pc. I will check the application on another pc tomorrow.

Erik

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

I just tested the application on a different pc with the same result. The application throws an exception (see attachment) and generates the correct output file. Can you provide my an example application?

Regards

Erik

Hi Erik,

Please find attached the sample application. Kindly change the license file path as appropriate.

Regards,

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

Sorry for the late reply. Your example works and I was able to locate the error in my application. For aspose.pdf.kit I accidental used an old license file name. Since I use the correct license file, everything works fine.

Thanks a lot for your support

Regards

Erik