'This file is damaged but is being repaired' after combining files with PdfFileEditor Concatenate

Hello,

I am combining multiple pdf files with the PdfFileEditor Concatenate function (memory stream array to single memory stream). See attached file for cut-down code.


The resulting pdf always brings up a message in Adobe Acrobat (reader or editor) that, ‘This file is damaged but is being repaired’.


The file opens ok but there is always a request to save the repaired file on closing Acrobat. I want to avoid this request to save so need to create an ‘undamaged’ file.


At the moment I am just saving the byte array from PdfFileEditor Concatenate memstream output with a ‘.pdf’ file extension. Do I need to finalize it somehow? I have tried creating a pdf document object from the memstream and then saving that but same problem.


Aspose pdf is version 9.5.0.0.




Thanks!

Hi Simon,


Thanks for your inquiry. I have tested the concatenation scenario with streams using Aspose.Pdf for .NET 10.3.0 and noticed that Adobe Acrobat asks to save PDF file on closing. But I am unable to notice “The file is damaged but is being repaired” message. Please find attached sample output file and confirm whether is it the issue you want to share, so we will investigate it accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hello,
Yes, that is exactly the problem we are facing.
I think if you construct a larger pdf then you will see the ‘The file is damaged…’ message as Acrobat takes a moment to process it.

Thanks for investigating!

Hi Simon,


Thanks for contacting support.

The problem appears to be occurring when saving ByteArray from MemoryStream instance which holds merged output from Concatenate(…) method. However we suggest you to directly pass FileOutputStream object as an argument to Concatenate(…) method, instead of using MemoryStream instance. In case the problem still persists, please share some sample application so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hello,

Unfortunately we do not want to create extra files on the filesystem (i.e. using FileStream in C#) as the pdf being concatenated may be confidential. MemoryStream is preferred.

Your colleague Tilal Ahmad has recreated the problem exactly so I don’t think you need a sample application from us.
Thanks for your help!

Hello,

I can confirm that Concatenate does work with array of FileStream but this is not a good solution for us. Is the problem with MemoryStream something you will be able to fix?

Thanks!

Hi Simon,


Thanks for your feedback. I have tried to concatenate large PDF files but still unable to notice the warning message “The file is damaged but is being repaired”.

However, I have logged a ticket PDFNEWNET-38530 in our issue tracking system for warning message on closing of merged PDF document. We will keep you updated about its resolution progress.

We are sorry for the inconvenience caused.

Best Regards,

Hello,

I have been able to work around this problem. It seems that writing to MemoryStream is simply adding a lot of extra rubbish data to the stream. Restricting what is read back from the stream (C# .ToArray or, better, restricted length .GetBuffer) allows a valid pdf file to be constructed (Acrobat does not complain or ask to save after viewing).

Thanks for your help!

Hi Simon,


Thanks for your feedback. It is good to know that you have managed to resolve the issue. We have recorded your findings and will consider it in the issue analysis.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-38530) have been fixed in Aspose.Pdf for .NET 10.4.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.