We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Damaged PDF after concatenation?

Hello - I have the following code:

public Stream GenerateReport(Stream sourceTemplate, IList<IDictionary> reportPages)
{
Settings.Strategy = FileProcessingStrategy.OptimizeMemoryUsage;

IList pages = new List();

reportPages.ToList().ForEach(page =>
{
MemoryStream currentPageOutput = new MemoryStream();
Form form = new Form(sourceTemplate, currentPageOutput);
sourceTemplate.Position = 0;

page.ToList().ForEach(field =>
{
form.FillField(field.Key, field.Value != null ? field.Value : string.Empty);
});

form.FlattenAllFields();
form.Save();

currentPageOutput.Flush();
pages.Add(currentPageOutput);

});

Stream outputStream = new MemoryStream();
PdfFileEditor editor = new PdfFileEditor();

if (pages.Count > 1)
editor.Concatenate(pages.ToArray(), outputStream);
else
return pages[0];

return outputStream;
}

The idea is that I want to pass into this method, a stream containing a PDF form and a list containing a dictionary of field names/values to apply to the form. Each dictionary element in the list represents a separate page in the final PDF. So, first I loop through the list of dictionaries. For each dictionary, I create a new memory stream to store a new PDF based on the template passed into the method. I then loop through each entry in the current dictionary and fill the form fields. I then flatten, save, flush and add that stream to a list. After completing this for all items in the list of dictionaries, I attempt to concatenate the streams in the list of streams and return the resulting stream of all pages.

What I'm seeing is that when I call Concatenate on a list of streams, the resuling PDF is damaged when I open it and view the second page. The PDF itself is fine, but Acrobat reports that it is damaged.

I tried working with only one dictionary, and thus only one PDF and no need to concatenate. I hadded a check at the end of my method to skip the concatenation if there was only one page. When I do this, the resulting PDF is filled with NULL characters, rather than the actual PDF content.

Any insight into what's going on here would be appreciated. I'm attaching my source template, the resulting damaged PDF and the resulting NULL filled PDF.

Thanks!

Chris

Hello Chris,

I have tried reproducing the problem by entering information over one of the field over the template PDF form that you have shared and have called the FlattenAllField(..) method and as per my observations, I am unable to notice the problem.

As per statement over 263443, is this problem also resolved ?

We apologize for the delay and inconvenience.

Hi Nayyer -

Yes, 263443 is resolved.

Regarding my current issue that you are unable to reproduce, can you please verify that you're running in a comprable environment to mine? I've been able to reproduce this issue on three systems so far. Two of the systems are as follows:

Windows 7 64 bit
.Net 4.0
Console application running through Visual Studio 2010 debugger
Using Aspose.Pdf.Kit 4.9.0.0 for .Net 4.0 (not client profile)

The third system is:

Windows Server 2008 R2 64 bit
.Net 4.0
WCF Service hosted in WAS in a 32 bit application pool
Using Aspose.Pdf.Kit 4.9.0.0 for .Net 4.0 (not client profile)

I understand that if you're not able to reproduce the problem then you can't offer a fix, however if we're unable to get a resolution to this issue, we will have to look at using a different component.

Thanks!

Chris

Hello Chris,

Thanks for the detailed information.

In my earlier try, I have tested the scenario using Aspose.Pdf.Kit for .NET 4.9.0 for .NET 2.0 over Windows7 Enterprise 64Bit while using a Windows Application developed in Visual Studio 2008 and I was unable to notice the problem. However, I will try replicating this issue over Windows 7 Enterprise 64Bit with Visual Studio 2010 and will share my findings accordingly.

We apologize for your inconvenience.

Hi Nayyer -

Just wanted to follow up and see if you have any update on this.

Thanks!

Chris

Hi Chris,

Please share a small working sample with us, so we could reproduce the issue using your particular scenario. You’ll be updated with the results accordingly.

We’re sorry for the inconvenience.
Regards,

Hi - Just wanted to follow up on this. We received our Aspose.Pdf.Kit license last week and now that we're using that, we no longer see this problem.

Chris

Hi Chris,

I’m glad to know that your issue is resolved; if you find any further questions or concerns, please do let us know.

Regards,