PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Exception during opening compressed PDF
https://forum.pdfsharp.net/viewtopic.php?f=3&t=1730
Page 1 of 1

Author:  jacekdt [ Wed Aug 03, 2011 8:15 am ]
Post subject:  Exception during opening compressed PDF

PdfSharp throws exception during loading compressed PDF document. I am not sure if all compressed documents but I have tested on pdfs generated by Microsoft Reporting Services 2008.

I have found the problem in PdfSharp.Pdf.IO.Lexer class in method ReadStream.

I have changed it to below code and the compressed pdf are processed correctly now:
Code:
 public byte[] ReadStream(int length)
    {
      MoveToNonWhiteSpace();
      pdf.Position = idxChar;
      byte[] bytes = new byte[length];
      int read = this.pdf.Read(bytes, 0, length);
      Debug.Assert(read == length);
      // synchronize idxChar etc.
      this.Position += length;
      return bytes;
    }


Can any body incorporate that changes in PDFSharp for future releases.
If required I can send example of pdf file which can not be opened.

Author:  DaveT [ Fri Aug 26, 2011 6:46 pm ]
Post subject:  Re: Exception during opening compressed PDF

Awesome!! Worked like a charm. Thanks.
Dave

Author:  mike.z [ Fri Jan 11, 2013 1:54 pm ]
Post subject:  Re: Exception during opening compressed PDF

Thanks jacekdt - very very much appreciated.

I was also having the problem of a blank PDF being created when I was using PDFSharp to merge PDF's created from .rdlc reports.

To clarify for anyone else having this issue, it is still present in the PDFSharp code & binaries as at 2013-01-11, version 1.32.

To apply the fix that jacekdt came up with, download the source code, open the file:
\PDFSharp\code\BuildAll-PdfSharp-VS2010.sln
(you'll need Visual Studio 2010)

Then in the project, expand the folder:
PdfSharp.Pdf.IO

and open the class:
Lexer.cs

Simply replace the existing ReadStream function with the code that jacekdt posted above.

Rebuild the solution, and you'll have a new binary to include in the \bin folder of your own project.


Cheers,
Mike

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/