Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
DeleteAnnotation |
Post Reply ![]() |
Author | |
John ![]() Beginner ![]() Joined: 04 May 12 Status: Offline Points: 2 |
![]() ![]() ![]() ![]() ![]() 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 |
|
![]() |
|
Ingo ![]() Moderator Group ![]() ![]() Joined: 29 Oct 05 Status: Offline Points: 3530 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
John ![]() Beginner ![]() Joined: 04 May 12 Status: Offline Points: 2 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store