V4.3.0.0 - PdfFileEditor.Concatenate closes MemoryStream

The following code throws an exception in v4.3.0.0 because the Concatenate method now closes the output Stream before returning. This code worked in all previous versions.

var outStream = new MemoryStream();
var pdfEditor = new PdfFileEditor();
pdfEditor.Concatenate(inStreams.ToArray(), outStream);
outStream.Position = 0;

Hi Paul,

We’re sorry for the inconvenience.

Please find attached the hot fix for this issue.

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

Hi,


Thanks for the quick update. Unfortunately the pdfStreams created by this hotfix are corrupt and can’t be opened by Acrobat Reader.

Hi Paul,

I have reproduced and logged this issue as PDFKITNET-15674 in our issue tracking system. Our team is looking into this issue and you’ll be updated with a resolution the earliest possible.

In the meanwhile, you can try using FileStreams or the files from the disk using file paths.

We’re sorry for the inconvenience.
Regards,

Hi Paul,

Can you please share the sample code snippet and the PDF files you’re working with? It looks like the problem is with the use of the Aspose.Pdf.Kit for .NET or the particular files. We’ll test the issue at our end using your scenario and you’ll be updated accordingly.

We’re sorry for the inconvenience.
Regards,

I too am having a problem with the concatenate method in version 4.3.0.0

I am using the following code (all 3 parameters are memory stream):
if (_file.memStream_PDF != null)
edt.Concatenate(currentPDF, _file.memStream_PDF, pdfOutput);

This causes the following error:
System.ObjectDisposedException: Cannot access a closed Stream.
at System.IO.__Error.StreamIsClosed()

I need to use MemoryStreams in this instance and can not save to file.

Hi Eric,

Did you try the latest hot fix shared above in this post? If you haven’t tried it yet at your end then please download the hot fix 4.3.0.2 and test the issue with that.

If you still find any issues, please do let us know.

We’re sorry for the inconvenience.
Regards,

It’s definitely not caused by the PDF files (it has worked in every version of Aspose.PDF since version 2.0.0.0!) and the code has not changed either. I’d say it is more likely that v4.3.0.0 and v4.3.0.2 do not support this scenario correctly any more.


It is difficult to post all the code but the scenario is populating PDF forms, concatenating them and then streaming them back to the client via the web browser. Here is some pseudo-ish type code:

using Aspose.Pdf.Kit;
public MemoryStream GetIndividualOutputStream()
{
var outputStream = new MemoryStream();
var newForm = new Form(_path, outputStream);
// Populate form
newForm.Save();
outputStream.Position = 0;
return outputStream;
}
public MemoryStream GetCombinedOutputStream()
{
var pdfFileEditor = new PdfFileEditor();
var inStreams = new List();

// Get individialOutputStreams for each document
var outStream = new MemoryStream();
pdfFileEditor.Concatenate(inStreams.ToArray(), outStream);
outStream.Position = 0;
return outStream;
}
// ASP.NET MVC
public ActionResult Pack()
{
var stream = GetCombinedOutputStream();
return File(stream, “application/pdf”, “Pack.pdf”);
}

I didn't try the HotFix yet because the previous posts indicated that it produced corrupt pdf files. I will try it now and see what happens.

I tried the hotfix. It doesn’t error out but it doesn’t concatenate anything either. I reverted back to v4.2.0 and the concatenation works.

Robert Ruggio:
I tried the hotfix. It doesn't error out but it doesn't concatenate anything either. I reverted back to v4.2.0 and the concatenation works.


Hi Eric,

Please share the code snippet you're using at your end, so we could test the issue using your scenario. You'll be updated accordingly.

We're sorry for the inconvenience.
Regards,

PaulCox:
It's definitely not caused by the PDF files (it has worked in every version of Aspose.PDF since version 2.0.0.0!) and the code has not changed either. I'd say it is more likely that v4.3.0.0 and v4.3.0.2 do not support this scenario correctly any more.

It is difficult to post all the code but the scenario is populating PDF forms, concatenating them and then streaming them back to the client via the web browser. Here is some pseudo-ish type code:


Hi Paul,

Thank you very much for sharing the code snippet. We'll test the issue using your scenario and share the results with you shortly.

We're sorry for the inconvenience.
Regards,

shahzad.latif:
Robert Ruggio:
I tried the hotfix. It doesn't error out but it doesn't concatenate anything either. I reverted back to v4.2.0 and the concatenation works.


Hi Eric,

Please share the code snippet you're using at your end, so we could test the issue using your scenario. You'll be updated accordingly.

We're sorry for the inconvenience.
Regards,

I am still using the following code (worked in v4.2.0 but not in the v4.3.x). All parameters to the Concatenate method are memory streams

if (_file.memStream_PDF != null)
edt.Concatenate(currentPDF, _file.memStream_PDF, pdfOutput);

shahzad.latif:
Robert Ruggio:
I tried the hotfix. It doesn't error out but it doesn't concatenate anything either. I reverted back to v4.2.0 and the concatenation works.


Hi Eric,

Please share the code snippet you're using at your end, so we could test the issue using your scenario. You'll be updated accordingly.

We're sorry for the inconvenience.
Regards,

I am still using the following code (worked in v4.2.0 but not in the v4.3.x). All parameters to the Concatenate method are memory streams

if (_file.memStream_PDF != null)
edt.Concatenate(currentPDF, _file.memStream_PDF, pdfOutput);

Hi Eric,

Thank you for pointing this out. We’ll test it at our end and update you the earliest possible.

We’re sorry for the inconvenience.
Regards,

Additional info...

After calling the Concatenate method and looking at the length of the pdfOutput stream the length = 0:

?pdfOutput.Length returns 0

Hi Eric,

Thank you very much for sharing the additional information. We’re testing the issue at our end and you’ll be updated as soon as possible.

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

Hi Paul and Eric,

We have further investigated this issue at our end using V. 4.3.0.2 , but couldn’t notice any problem. Can you guys please share small sample projects along with the sample files which can reproduce the issue at our end? I would like to share that it is very important for our team to reproduce the issue at our end, by using your scenario, in order to resolve it.

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

Hi Shahzad,


Could you get your developers to share a small sample project first? It would be easier for us to have a project that is known to work than trying to extract code from a large solution.

Regards,
Paul.

Hi Paul,

Please find attached the sample project to test the issue at your end. You need to add the reference to V. 4.3.0.2 and change the file names as required.

If this code doesn’t work at your end, please do let us know.
Regards,