Hi Mel,
I have received the following feedback from our development team which I would like to share with you. Hopefully, this will help you in resolving your issue.
In v6.5, all the data of stream objects of the document were loaded into memory when concatenation operation was performed. This approach required a large size of allocated memory.
To avoid extra memory allocation algorithm was improved after version 6.5: stream objects are not loaded into memory but just copied from source document into destination document at document save process.
This means that all data of source document must be accessible when result document is saved.
That’s why concatenating document and storing result into source stream may get incorrect result.
In other word the following code may work incorrectly:
PdfFileEditor pfe = new PdfFileEditor(); pfe.Concatenate(srcStream, otherStream, srcStream);
You should redesign your code to avoid this situation. e.g.
Modify AppendPdf to return new stream object:
public void Stream AppendPdf(Stream stream, string targetFile)
{
Stream result = new MemoryStream();
PdfFileEditor pfe = new PdfFileEditor();
using(Stream fileStream = File.OpenRead(targetFile))
{
pfe.Concatenate(stream, fileStream, result);
}
return result;
}
Use these lines of code:
Stream targetStream = createEmptyFile();
targetStream = AppendPdf(targetStream, "file1.pdf");
targetStream = AppendPdf(targetStream, "file2.pdf");
But a better solution is to use concatenation of multiple files:
pfe.Concatenate(new string[] { "file1.pdf", "file2.pdf", "file3.pdf"}, resultFile); \ (or use version of concatenate method with streams).
This approach will be more efficient because it will not require multiple loading and saving PDF document from/to streams.
Please perform the above modification and let us know if you still face any issue.
Sorry for the inconvenience,