Print Page | Close Window

DeleteAnnotation

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=2254
Printed Date: 14 Aug 25 at 6:01AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DeleteAnnotation
Posted By: John
Subject: DeleteAnnotation
Date Posted: 04 May 12 at 3:50AM
Hello
 
The following works without a problem:
a) lnstantiate QPDF
    tempQPDF := TQuickPDF.Create;
b) create a new content stream (layer)
    tempQPDF.NewContentStream;
c) render a page to stream
    tempQPDF.RenderPageToStream(tempDPI, tempQPDF_PageNum, 1, tempMemoryStream);
d) draw an annotation on the rendered page
    DrawBox(tempAnnotLeft, tempAnnotTop, tempAnnotWidth, tempAnnotHeight, 1);
e) then save the pdf file.
 
Question:
When I reopen the saved pdf file and render the page on which I placed the annotation, tempQPDF.AnnotationCount returns 0.
 
My goal is to delete all of the annotations on the page with the code below.
 
procedure TformImageEnPDF.SpeedButton1Click(Sender: TObject);
var
  I: Integer;
begin
showmessage('test' + #13 +
            'CurrentPage = ' + IntToStr(tempQPDF.SelectedPage) + #13 +
            'AnnotationCount = ' + IntToStr(tempQPDF.AnnotationCount));
  with tempQPDF do
    begin
      for I := 1 to AnnotationCount do
        begin
          DeleteAnnotation(I);
        end;
    end;
end;
Suggestions ??
 
TIA
 
John
 
 
 
 



Replies:
Posted By: Ingo
Date Posted: 04 May 12 at 6:38AM
Hi John!

"...
d) draw an annotation on the rendered page  
 DrawBox(tempAnnotLeft, tempAnnotTop, tempAnnotWidth, tempAnnotHeight, 1);
..."

This draws a box on the page - nothing more and no real annotation ;-)
If you want to insert a real annotation you should use
AddNoteAnnotation
Please read here:
http://www.quickpdflibrary.com/help/quickpdf/AddNoteAnnotation.php
And all about annotations in general here:
http://www.quickpdflibrary.com/help/quickpdf/AnnotationsAndHotspotLinks.php

Cheers and welcome here,
Ingo





Posted By: AndrewC
Date Posted: 04 May 12 at 1:05PM
John,  

When you delete annotations or formfields then you need to delete them backwards.  This is when you delete an annotation then the total number of annotations reduced by 1.   This is why the loop must be backwards.

procedure TformImageEnPDF.SpeedButton1Click(Sender: TObject);
var
  I: Integer;
begin
showmessage('test' + #13 +
            'CurrentPage = ' + IntToStr(tempQPDF.SelectedPage) + #13 +
            'AnnotationCount = ' + IntToStr(tempQPDF.AnnotationCount));
  with tempQPDF do
    begin
      for I := AnnotationCount downto 1 do  // step - 1  <<<<<<<<<<<<<<<<<<<<<<<<
        begin
          DeleteAnnotation(I);
        end;
    end;
end;

Andrew


Posted By: John
Date Posted: 08 May 12 at 2:24PM
Ingo
 
Thanks for the reply.
 
To clarify, my first post.
a) Each PDF opened, is associated with a database record which stores the original content stream count. 
b) This allows me to know the content stream number of the layer/stream that I created when the PDF was originally opened and select that content stream when the pdf is loaded.
c) All drawboxes or putlines placed on an existing PDF are placed on the content stream that I created when the PDF was original opened.
 
If I render a page, delete the content stream on which I had previously placed a drawbox, save the PDF and rerender the page, the drawbox I had previously placed is gone.  This action is as expected.  I can then repeat this process of rendering the page, placing a new drawbox, resaving the PDF, viewing the redrawn drawbox and then again deleting the redrawn drawbox. 
 
All of the viewing, drawing and deletion is done from a single instantiation of a delphi form which does the following from the OnCreate event of the form
a) Instantiates an instance of QuickPDF,
b) loads the PDF document via tempQuickPDF.LoadFromFile and
c) sets the active stream/layer via a to call tempQuickPDF.SelectContentStream.
 
Question:
How is it that I can repeatedly place a drawbox on a selected content stream and then delete the stream without either reloading the entire document or recreating the instantiation of tempQuickPDF?  Does each rerendering of the page recreate all of the content streams (even those previously deleted) based on some variable that was defined when the pdf document was loaded into the instantiation of the tempQuickPDF?
 
TIA
 
John
 


Posted By: AndrewC
Date Posted: 08 May 12 at 3:23PM
Each content stream contains drawing commands.  When the PDF renders it processes each contentstream 1 after the other and draws what is contained in the each stream. 

Because the contentsteams contain the only copy of the drawing commands they cannot be recreated.  The only way they can be recreated is by reloading the file.

As Ingo points out,  DrawBox draws a graphical rectangle onto the page.  A rectangle is not a true PDF Annotation object.  You need to use AddNoteAnnotation to add a proper annotation which is a special separate object that is not included in the content stream but is stored in a list of Annotations.  Annotations are always drawn after all of the contentstreams have been drawn.

Andrew.



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