Hi,
I've got a PDF file that lead me to several conclusions and some questions:
When trying the delivered Booklet example first I've got an exeception in the PdfSharp.Pdf.Filters.Filter.RemoveWhiteSpace method and I'm convinced that it never worked as originally written. My suggested correction is here:
Code:
protected byte[] RemoveWhiteSpace(byte[] data)
{
int count = data.Length;
int j = 0;
for (int i = 0; i < count; i++, j++)
{
switch (data[i])
{
case (byte)Chars.NUL: // 0 Null
case (byte)Chars.HT: // 9 Tab
case (byte)Chars.LF: // 10 Line feed
case (byte)Chars.FF: // 12 Form feed
case (byte)Chars.CR: // 13 Carriage return
case (byte)Chars.SP: // 32 Space
j--;
break;
default:
if (i != j)
data[j] = data[i];
break;
}
}
if (j < count) // MM correction
{
byte[] temp = data;
data = new byte[j];
for (int idx = 0; idx < j; idx++)
data[idx] = temp[idx];
}
return data;
}
After that I've got another exception, this time in the PdfSharp.Pdf.Filters.ASCIIHexDecode.Decode method, where originally was
Code:
count <<= 2;
but I'm convinced it should be
Code:
count /= 2;
After that the code has passed into the PdfSharp.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Read method where the inf.Inflate method throws the PdfSharp.SharpZipLib.SharpZipBaseException: Adler chksum doesn't match: 1526531981 vs. 91641681.
Unfortunately I'm not that familiar with the PDF content handling to be able to localize the cause of this issue. The fixes I've provided were only the obvious ones to make the code continue without exceptions.
I've got also yet another file (which I don't think I can expose here due to it's content) and with that I'm getting another exception at the same place: PdfSharp.SharpZipLib.SharpZipBaseException: broken uncompressed block. I don't know, why in this case the inf.Inflate method was called with the b {byte[32768]} array of zeroes.
I believe it all relates to this part of the core:
Code:
// Import resources
PdfItem res = importPage.Elements["/Resources"];
if (res != null) // unlikely but possible
because actually all the files I have to process have this "unlikely" Element.
Could someone have a look at the attached file and using the delivered Booklet example to debug the core of PdfSharp. Any (especially prompt) response would be greatly appreciated.
Thank you in advance,
Mirek
P.S. I've tried to attach the pdf file, but this forum responses that the image file has invalid format...