Print Page | Close Window

Bug with comments in pdfs

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1055
Printed Date: 25 Jun 25 at 5:51PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Bug with comments in pdfs
Posted By: ukobsa
Subject: Bug with comments in pdfs
Date Posted: 07 Apr 09 at 4:18AM
Hi,

if there are comments in a pdf then reading data can go wrong:

TPDFStructure.SmartDecode checks for whitespace and comments but it ignores that after a comment there may be additional whitespace:


trailer
<< /ID
% ReportLab generated PDF document -- digest (http://www.reportlab.com)
[(4\264\331\222\333\020\213K\351^\240\316\000\203\255\301) (4\264\331\222\333\020\213K\351^\240\316\000\203\255\301)]

/Info 7 0 R
/Root 6 0 R
/Size 18 >>


in this sample the trailer is not read correct as after the first comment and start of ID data there is additional whitespace

Fix:

procedure SkipWhitespace;
begin
    // Read all whitespace
    while (X < L) and IsWhitespace(Source[X]) do Inc(X);

    // is next char the start sign for a comment, then ignore entire line
    if (X < L) and (Source[X] = '%') then
    begin
      while (X < L) and (Source[X] <> #10) and (Source[X] <> #13) do Inc(X);
      if (Source[X] = #13) and (Source[X + 1] = #10) then
        Inc(X, 2)
      else
        Inc(X);

      // UKO 2009-04-07 after a comment recheck for white space!
      SkipWhitespace;
    end;
end;


same should be done on TPDFType1Decoder.Tokenize: also adjust the SkipWhiteSpace procedure





Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk