Welcome Guest Search | Active Topics | Sign In | Register

Merged PDFs failing to save to stream Options
MJH
Posted: Friday, December 7, 2012 5:32:00 AM
Rank: Newbie
Groups: Member

Joined: 12/7/2012
Posts: 6
Hi,

Trying to merge PDF documents together and then save the result to a memory stream. The code works for the majority of documents but for one particular document it throws the exception:
'Found invalid data while decoding'.

Tried upgrading to a more recent version of the .dll, which throws a different exception:
'Block length does not match with its complement'.

I'll email you the 2 test PDFs shortly.

Test code:
Code: C#
string fname1 = @"C:\Test1.pdf";
string fname2 = @"C:\Test2.pdf"; //  The document that causes the issue

PdfDocument.Merge(fname1, fname2);

PdfDocument doc = new PdfDocument(fname1);

using (MemoryStream ms = new MemoryStream())
{
         doc.Save(ms); // Exception here
                                 //  ... REST OF MY CODE
}


Stack trace:
at System.IO.Compression.Inflater.DecodeUncompressedBlock(Boolean& end_of_block)
at System.IO.Compression.Inflater.Decode()
at System.IO.Compression.Inflater.Inflate(Byte[] bytes, Int32 offset, Int32 length)
at System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count)
at EO.Pdf.Internal.jw.a(Byte[] A_0)
at EO.Pdf.Internal.jw.b(Byte[] A_0, Stream A_1, ah A_2, Int32 A_3)
at EO.Pdf.Internal.h3.b(Byte[] A_0, String A_1, ah A_2, Int32 A_3)
at EO.Pdf.Internal.h3.d()
at EO.Pdf.Internal.d3.b()
at EO.Pdf.Contents.PdfContentContainer.k()
at EO.Pdf.StructTreeRoot.SyncWithPageContent(PdfPage page)
at EO.Pdf.PdfDocument.a()
at EO.Pdf.PdfDocument.Save(Stream stream)

Thanks for the help!
MJH
eo_support
Posted: Friday, December 7, 2012 3:10:34 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

This might be one of the files that we will not be able to merge. Some PDF file uses zip compression to compress certain data blocks, and we use MS unzip code to unzip it. If the compressed data block is invalid, then you will have this error. In that case the only option is to fix the original PDF file.

Thanks!
MJH
Posted: Monday, December 10, 2012 4:48:20 AM
Rank: Newbie
Groups: Member

Joined: 12/7/2012
Posts: 6
Hi there again,

Thanks for your reply, I can see why this would be an issue. Though, these PDFs are published by financial houses and are used regularly within the industry - so it ought to be possible to merge them. Either way we can't change the files... It'd be good if you could have a look at them.

Thanks again,

MJH
eo_support
Posted: Monday, December 10, 2012 10:02:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

There is no way for us to make it work if the data is already corrupted. The most we can do is to change our code to be more tolerate so that even if the data is corrupted, the merge will still succeed --- but some part of the result file may be wrong, for example, content for one page maybe missing, etc. Please let us know if that is acceptable for you.

Thanks!
MJH
Posted: Tuesday, December 11, 2012 4:54:50 AM
Rank: Newbie
Groups: Member

Joined: 12/7/2012
Posts: 6
Hi support,

Yeah, that sounds acceptable. Thanks for your help!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.