PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 8:03 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Oct 13, 2011 7:41 am 
Offline

Joined: Thu Oct 13, 2011 7:23 am
Posts: 2
Hey there,
i've already read 2 times about it in this forum, and someone even posted a solution too, but i wanted to show you my exactly problem and the solution to it.

First of all to say: PDF is created by ReportViewer.LocalReport.Render()-Method and saved as MemoryStream, so i cannot provide it here :)
(Plus i cannot easily save it WHEN the error occurs... when i am able to save it, the whole file already changed again and error "disappeared"... more or less, but read on to understand)

As the topic says, i got stuck in an infinite loop in ScanHexadecimalString-Method (Lexer.cs). My Problem there was a special character, that is number 174 (the "R" in a circle)
simple "skipping" the unreadable character, as the other solution (and the only real one) i found, fixed it, but might lead to "unexpected behavior" or whatever.
So i debugged a little bit and noticed, that the Lexer.ReadStream()-Method returns a wrong byte[]
Somehow i wondered, because it starts with CR and LF and the last 2 characters of the real stream (looked it up in Notepad++) were missing.
I found out that after the "stream" keyword (or whatever you call it) there is a single whitespace. Because of this, the CR and LF isn't skipped, how it was intended there (that is what the comment says)

Quick fix for me:
change
Code:
public byte[] ReadStream(int length)
{
   int pos = 0;
   // Skip new line behind «stream»
   if(this.currChar == Chars.CR)
   {
      if(this.nextChar == Chars.LF)
         pos = this.idxChar + 2;
      else
         pos = this.idxChar + 1;
   }
   else
      pos = this.idxChar + 1;

   this.pdf.Position = pos;
   byte[] bytes = new byte[length];
   int read = this.pdf.Read(bytes, 0, length);
   Debug.Assert(read == length);
   // synchronize idxChar etc.
   this.Position = pos + length;
   return bytes;
}
to
Code:
public byte[] ReadStream(int length)
{
   int pos = 0;
   // Skip new line behind «stream»
   MoveToNonWhiteSpace();
   if(this.currChar == Chars.CR)
   {
      if(this.nextChar == Chars.LF)
         pos = this.idxChar + 2;
      else
         pos = this.idxChar + 1;
   }
   else
      pos = this.idxChar + 1;

   this.pdf.Position = pos;
   byte[] bytes = new byte[length];
   int read = this.pdf.Read(bytes, 0, length);
   Debug.Assert(read == length);
   // synchronize idxChar etc.
   this.Position = pos + length;
   return bytes;
}
in Lexer.cs

still i don't understand why it only stucks this one time, because all streams are read wrong...
anyway, should be fixed :)

//EDIT:
short after posting, i even realised you could now remove the whole if-else part, because MoveToNonWhitespace() skips CR and LF too :D
Code:
// Skip new line behind «stream»
MoveToNonWhiteSpace();
byte[] bytes = new byte[length];
int read = this.pdf.Read(bytes, 0, length);
Debug.Assert(read == length);
// synchronize idxChar etc.
this.Position = pos + length;
return bytes;
(just an idea and not tested yet)


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 20 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