PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Oct 31, 2024 11:08 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Jan 14, 2009 2:23 am 
Offline

Joined: Wed Jan 14, 2009 2:10 am
Posts: 7
Location: London, United Kingdom
Scenario:

A Microsoft SQL 2008 Database with Report Services (version 10) generates a PDF report. The report is 1 page long, some basic text, nothing fancy.

Using .Net code, the PDF is opened and saved, the result is a blank PDF (blank as viewed in Adobe PDF Reader 8, i.e., the content has been lost when the PDF goes through PDFSharp).

If I change the document title, default zoom etc, these settings are saved, but the PDF is still blank.

The same report, as generated per the previous version of SQL report services (version 9) runs through PDFSharp normally.

If I try to merge a PDF into the background of that report, like a PDF with a formatted header/footer using the code...

Code:
Dim gfx As XGraphics = XGraphics.FromPdfPage(FirstPage, XGraphicsPdfPageOptions.Prepend)


...an exception is encountered when the above line of code is called. (This error doesn't occour on v9 PDFs, only since v10 was introduced)...


Code:
PdfSharp.SharpZipLib.SharpZipBaseException: Header checksum illegal
  at PdfSharp.SharpZipLib.Zip.Compression.Inflater.DecodeHeader() in PDFsharp\code\PdfSharp\PdfSharp.SharpZipLib\Zip\Compression\Inflater.cs:line 247
  at PdfSharp.SharpZipLib.Zip.Compression.Inflater.Decode() in PDFsharp\code\PdfSharp\PdfSharp.SharpZipLib\Zip\Compression\Inflater.cs:line 427
  at PdfSharp.SharpZipLib.Zip.Compression.Inflater.Inflate(Byte[] buf, Int32 offset, Int32 len) in PDFsharp\code\PdfSharp\PdfSharp.SharpZipLib\Zip\Compression\Inflater.cs:line 711
  at PdfSharp.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Read(Byte[] b, Int32 off, Int32 len) in PDFsharp\code\PdfSharp\PdfSharp.SharpZipLib\Zip\Compression\Streams\InflaterInputStream.cs:line 409


Microsoft must have done something that upsets PDFSharp with their new rendering engine for PDFs, at this stage I am unsure which side the bug is in.

The PDF version of the report services pdf is 1.3 (Acrobat 4x).

Any suggestions?
Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 14, 2009 10:32 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3111
Location: Cologne, Germany
Hi!

We need a PDF file to replicate the problem.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 14, 2009 2:17 pm 
Offline

Joined: Wed Jan 14, 2009 2:10 am
Posts: 7
Location: London, United Kingdom
Yes that would be handy, here is the PDF, it's directly out of Report Services 10.

http://cid-6e64738c64f8f959.skydrive.live.com/self.aspx/Public/101O.pdf

To get PDFSharp to make it into a blank PDF...

Code:
Imports PdfSharp
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Imports PdfSharp.Drawing

Dim cStatement As PdfDocument = PdfReader.Open(FilePathToPDF)
cStatement.Info.Subject = "An example change."
cStatement.Save(FilePathToPDF)


The subject text is preserved in the blank pdf.

To create the checksum exception...

Code:
Dim lMerge As XPdfForm = XPdfForm.FromFile(OverlayPDFFilePath)
Dim FirstPage As PdfPage = cStatement.Pages(0)
Dim gfx As XGraphics = XGraphics.FromPdfPage(FirstPage, XGraphicsPdfPageOptions.Prepend)

Dim width As Double = FirstPage.Width
Dim height As Double = FirstPage.Height

Dim box As XRect = New XRect(0, 0, width, height)
gfx.DrawImage(lMerge, box)

cStatement.Save(FilePath)


The purpose of the above code is to merge a PDF containing a letterhead onto the target PDF document. The letterhead PDF has been working fine with PDFSharp. The letterhead is only merged onto page 1 of the document.

I hope this is usefull. Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Debug Output
PostPosted: Mon Jan 19, 2009 6:44 pm 
Offline

Joined: Wed Jan 14, 2009 2:10 am
Posts: 7
Location: London, United Kingdom
Have been playing around with the Report Services, the only configuration available is to enable compression (as disabled by default), as the error seems related to a ZIP checksum.

Would be terriffic to get this to work, as SQL Report Services 10 can render HTML as PDF, and is free.

I have observed the following debug output messages:

Quote:
UserOrOwnerPasswordRequired: 'At least a user or an owner password is required to encrypt the document.'
UnexpectedToken: 'Token '{0}' was not expected.'
UnknownEncryption: 'The PDF document is protected with an encryption not supported by PDFsharp.'


These messages only appear on the report services 10 PDF, and not the older v9s. There appears to be some unknown symbol (which isn't showing up in the debug message {0}), and curiously, the PDF isn't encrypted or protected.

Still investigating.


Top
 Profile  
Reply with quote  
 Post subject: Cannot trace.
PostPosted: Mon Jan 19, 2009 8:54 pm 
Offline

Joined: Wed Jan 14, 2009 2:10 am
Posts: 7
Location: London, United Kingdom
I couldn't trace where the encyption checking was done, but the exceptions seems to originate from Parser.cs

Code:
Symbol ReadSymbol(Symbol symbol)
    {
Symbol current = this.lexer.ScanNextToken();
          if (symbol != current)
             throw new PdfReaderException(PSSR.UnexpectedToken(this.lexer.Token));
          return current;
}


the ScanNextToken seems to encounter an unknown Symbol (not implemented"), the exception occours despite the code returning a Symbol.None.

Unsure how to examine the unrecognised symbol, if I break at the end of ScanNextToken() and look at the value for this.symbol in the VS Locals window, the value is set to "PdfSharp.Pdf.IO.Symbol.BeginStream", here are the other values. Setting to return Symbol.BeginStream instead of Symbol.None has no effect.


Quote:
- this {PdfSharp.Pdf.IO.Lexer} PdfSharp.Pdf.IO.Lexer
currChar 136 '?' char
idxChar 3498 int
nextChar 188 'ΒΌ' char
+ pdf {System.IO.FileStream} System.IO.Stream {System.IO.FileStream}
PdfLength 8825 int
pdfLength 8825 int
Position 3498 int
symbol BeginStream PdfSharp.Pdf.IO.Symbol
Symbol BeginStream PdfSharp.Pdf.IO.Symbol
+ token {} System.Text.StringBuilder
Token "" string
+ TokenToBoolean 'this.TokenToBoolean' threw an exception of type 'System.IndexOutOfRangeException' bool {System.IndexOutOfRangeException}
+ TokenToInteger 'this.TokenToInteger' threw an exception of type 'System.FormatException' int {System.FormatException}
+ TokenToReal 'this.TokenToReal' threw an exception of type 'System.FormatException' double {System.FormatException}
+ TokenToUInteger 'this.TokenToUInteger' threw an exception of type 'System.FormatException' uint {System.FormatException}
ch 136 '?' char


Removing the debug.asserts just results in the code completing without exception, but just giving me a blank PDF (which is larger in size than the original PDF put in).

Is a BeginStream Symbol abnormal?


Top
 Profile  
Reply with quote  
 Post subject: Status update.
PostPosted: Sat Feb 07, 2009 3:38 pm 
Offline

Joined: Wed Jan 14, 2009 2:10 am
Posts: 7
Location: London, United Kingdom
I've still not managed to find a solution to this.

Did anyone receive the PDF I sent over?

I notice a similiar Unknown Symbol problem was fixed in the support thread of this forum with just 2 lines of code, so I expect there must be a similiar solution for me?


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 10, 2009 11:10 am 
Offline

Joined: Tue Nov 10, 2009 11:07 am
Posts: 4
found this relating to itextsharp
http://social.msdn.microsoft.com/Forums ... 77950c386f
they say something about zip unrealted tokens in the object stream

maybe it helps


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 11:56 am 
Offline

Joined: Tue Nov 10, 2009 11:07 am
Posts: 4
the only difference between rs22008 pdfs and normal pdfs is simply
where the normal pdf has "stream" the rs2008 pdf has "stream "
with regex or something the rs pdf can be modified and then used


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 26, 2010 3:11 pm 
Offline

Joined: Mon Apr 26, 2010 3:03 pm
Posts: 1
I had exactly the same bug with PDF generated by SSRS and I fixed it by changing Lexer.cs a bit:

old code:
Code:
case "stream":
    return this.symbol = Symbol.BeginStream;

new code:
Code:
case "stream":
    if (this.nextChar == 32 || this.nextChar == 13 || this.nextChar == '\n')
        ScanNextChar();       
    return this.symbol = Symbol.BeginStream;


Top
 Profile  
Reply with quote  
PostPosted: Mon May 17, 2010 1:40 am 
Offline

Joined: Mon May 17, 2010 1:39 am
Posts: 1
thanks for the pointer Ronin, tested it out and it works a treat, cheers.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 02, 2010 7:53 pm 
Offline

Joined: Thu Sep 02, 2010 7:36 pm
Posts: 1
That fix will work about 99% of the time. However, if your stream data happens to begin with bytes 10, 13, or 32, it will skip over the beginning of your stream.

ReadStream() expects the reader to be positioned at the CR/LF following the "stream" keyword, so you need skip trailing spaces only.

Code:
   case "stream":
      while (ch == 32)
         ch = ScanNextChar();
      return this.symbol = Symbol.BeginStream;


Top
 Profile  
Reply with quote  
PostPosted: Mon May 09, 2011 8:10 am 
Offline

Joined: Mon May 09, 2011 8:02 am
Posts: 1
My solution - a combination of Ronin's version and the code supplied in [1] - is as follows:

Code:
case "stream":
  if (this.nextChar == 32) ScanNextChar();
  if (this.nextChar == 13) ScanNextChar();
  return this.symbol = Symbol.BeginStream;

HTH someone,
Gerald

[1] Export PDF in ssrs 2008 vs ssrs 2005 - pdf is different, won't work with itextsharp (possibly other PDF post-processing tools)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group