Print Page | Close Window

Find all annotations in a PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1225
Printed Date: 22 Nov 24 at 7:11PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Find all annotations in a PDF
Posted By: Rowan
Subject: Find all annotations in a PDF
Date Posted: 25 Sep 09 at 8:13AM
Programmatically retrieving a list of all the various annotations stored inside a PDF is pretty easy when using the http://www.quickpdflibrary.com/help/quickpdf/AnnotationCount.php - AnnotationCount and http://www.quickpdflibrary.com/help/quickpdf/GetAnnotStrProperty.php - GetAnnotStrProperty with Quick PDF Library. An example of how to do this is shown below in C# and Delphi.

C# Sample Code:

---
QP.LoadFromFile(txtFilePath.Text);

for (int i = 1; i <= QP.PageCount(); i++)
{
    QP.SelectPage(i);

    txtLog.Text = txtLog.Text + "Page " + Convert.ToString(i) + " has " + QP.AnnotationCount() + " annotations." + "\r\n" + "\r\n";
    
    for (int d = 1; d < QP.AnnotationCount(); d++)
    {
        string AnnotType = QP.GetAnnotStrProperty(d, 101);
        txtLog.Text = txtLog.Text + AnnotType + "\r\n";
    }
}
---

Delphi Sample Code:

---
Memo5.Lines.BeginUpdate;
Memo5.Lines.Clear;
ProgressBar1.Max := QP.PageCount;

for Page := 1 to QP.PageCount do
begin
  QP.SelectPage(Page);
  ProgressBar1.Position := Page;

  Memo5.Lines.Add('Page ' + IntToStr(Page) + ' has ' +
 IntToStr(QP.AnnotationCount) + ' annotations');
  for AnnotIndex := 1 to QP.AnnotationCount do
  begin
 AnnotType := QP.GetAnnotStrProperty(AnnotIndex, 101);
 Memo5.Lines.Add('Annot number ' + IntToStr(AnnotIndex) + ' on this page has type: ' + AnnotType);
  end;

  Memo5.Lines.Add('');
end;
---



Replies:
Posted By: Rowan
Date Posted: 12 Oct 09 at 1:34AM
This is an enhanced version of the Delphi Sample Code:

---
QP := TQuickPDFQVer.Create;
 try
   QP.UnlockKey(' ... ');
   QP.LoadFromFile('annots.pdf');

   for Page := 1 to QP.PageCount do
   begin
     QP.SelectPage(Page);
     Memo1.Lines.Add('Page ' + IntToStr(Page));
     for AnnotationIndex := 1 to QP.AnnotationCount do
     begin
       Memo1.Lines.Add('  Annotation ' + IntToStr(AnnotationIndex));
       Memo1.Lines.Add('    Type: ' +
         QP.GetAnnotStrProperty(
AnnotationIndex, 101));
       Memo1.Lines.Add('    Contents: ' +
         QP.GetAnnotStrProperty(
AnnotationIndex, 102));
       Memo1.Lines.Add('    Name: ' +
         QP.GetAnnotStrProperty(
AnnotationIndex, 103));
       Memo1.Lines.Add('    Subject: ' +
         QP.GetAnnotStrProperty(
AnnotationIndex, 127));
       Memo1.Lines.Add('    Left: ' +
         FormatFloat('0.00', QP.GetAnnotDblProperty(
AnnotationIndex, 105)));
       Memo1.Lines.Add('    In reply to: ' +
         FormatFloat('0.00', QP.GetAnnotIntProperty(
AnnotationIndex, 128)));
     end;
   end;
---



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