PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Watermark and scanned documents

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Bug Reports - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
opa



Joined: 03 Dec 2007
Posts: 8

PostPosted: Wed Mar 12, 2008 1:47 pm    Post subject: Watermark and scanned documents Reply with quote

Hello.

I'm trying to put watermark in a pdf document. After many tests, I have a problem with certain pdf documents. These documents are composed of pages with text, images and "scanned documents". In the pages that include "scanned documents" I recieve the "Unknown token 'QQ'" or "Unknown token 'DoQ'".

Can you help me?

Thanks for advance
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Mar 12, 2008 2:50 pm    Post subject: Reply with quote

Hi!
To replicate this problem we need a PDF file that causes this error.

I'll send you a PM with an e-mail address for file submission.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Thu Mar 13, 2008 8:06 am    Post subject: Reply with quote

Hello!

I can replicate the error, but other team members will have to fix it ...

I'll keep you informed.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
opa



Joined: 03 Dec 2007
Posts: 8

PostPosted: Thu Mar 13, 2008 9:57 am    Post subject: Watermark and scanned documents Reply with quote

Hi!

Thank you very much.

I'm trying to resolve it too.

Regards
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Mon Mar 17, 2008 9:56 am    Post subject: Reply with quote

Hello!

We found a solution for your problem.

In PdfContent.cs (around line 124) change method
"internal void PreserveGraphicsState()"
like this:
Code:
internal void PreserveGraphicsState()
{
  // If a content stream is touched by PDFsharp it is typically because graphical operations are
  // prepended or appended. Some nasty PDF tools does not preserve the graphical state correctly.
  // Therefore we try to relieve the problem by surrounding the content stream with push/restore
  // graphic state operation.
  if (this.Stream != null)
  {
    byte[] value = Stream.Value;
    int length = value.Length;
    if (length != 0 && ((value[0] != (byte)'q' || value[1] != (byte)'\n')))
    {
      byte[] newValue = new byte[length + 2 + 3];
      newValue[0] = (byte)'q';
      newValue[1] = (byte)'\n';
      Array.Copy(value, 0, newValue, 2, length);
      newValue[length + 2] = (byte)' ';
      newValue[length + 3] = (byte)'Q';
      newValue[length + 4] = (byte)'\n';
      Stream.Value = newValue;
      Elements.SetInteger("/Length", Stream.Length);
    }
  }
}


In file PdfContents.cs (around line 142) change method "void SetModified()" like this:
Code:
else if (count > 1)
{
  // Surround content streams with q/Q operations
  byte[] value;
  int length;
  PdfContent content = (PdfContent)((PdfReference)Elements[0]).Value;
  if (content != null && content.Stream != null)
  {
    length = content.Stream.Length;
    value = new byte[length + 2];
    value[0] = (byte)'q';
    value[1] = (byte)'\n';
    Array.Copy(content.Stream.Value, 0, value, 2, length);
    content.Stream.Value = value;
    content.Elements.SetInteger("/Length", length + 2);
  }
  content = (PdfContent)((PdfReference)Elements[count - 1]).Value;
  if (content != null && content.Stream != null)
  {
    length = content.Stream.Length;
    value = new byte[length + 3];
    Array.Copy(content.Stream.Value, 0, value, 0, length);
    value[length] = (byte)' ';
    value[length + 1] = (byte)'Q';
    value[length + 2] = (byte)'\n';
    content.Stream.Value = value;
    content.Elements.SetInteger("/Length", length + 3);
  }
}

_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
opa



Joined: 03 Dec 2007
Posts: 8

PostPosted: Tue Mar 18, 2008 4:11 pm    Post subject: Reply with quote

Hello!

I have updated the code and works correctly. Have solved all my problems.

Thank you very much.

Regards.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Bug Reports - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com