Print Page | Close Window

I need to find if a PDF file is encrypted

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=221
Printed Date: 29 Apr 24 at 6:57AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: I need to find if a PDF file is encrypted
Posted By: SuperDave
Subject: I need to find if a PDF file is encrypted
Date Posted: 22 Dec 05 at 5:04PM
Hi,
I am adding note annotations using QP.AddNoteAnnotation which works really well except if the file is encrypted the note comes out as garbage.
If I knew that a file is encrypted I could prevent the user from adding a note to it.
Anyone know of a function (even if it is not a QP function) that can find if a PDF is encrypted.
Thanks.



Replies:
Posted By: Ingo
Date Posted: 22 Dec 05 at 5:52PM
Hi Dave!
You can use the functions Encrypted and Unencrypt:

. . .

   try
      Save_Cursor   := Screen.Cursor;
      Screen.Cursor := crHourglass;    // Show hourglass cursor
      QP.UnlockKey('MyKey');
      QP.LoadFromFile(Edit1.text);
      If QP.Encrypted > 0 Then
        QP.Unencrypt;
//    doing anything here ...
   finally
      QP.Free;
   end;

. . .

If you need more details you can do something like this here:

. . .

       ecry.Text := IntToStr(QP.Encrypted);
       If ecry.Text = '0' Then
          ecry.Text := 'Nothing';
       If ecry.Text = '1' Then
          ecry.Text := 'Adobe Standard';
       If ecry.Text = '2' Then
          ecry.Text := 'Unknown';

. . .

All is in delphi.

To your problem: First looking if the file is encrypted, then unencrypt it and then you can do the annotation.



-------------
Cheers,
Ingo



Posted By: SuperDave
Date Posted: 22 Dec 05 at 6:56PM
Thanks Ingo!
Your help is really useful to me.
I now have notes adding to encrypted PDFs and have also managed to re-encrypt them using the encryptwithfingerprint function.
You're a Star Ingo.



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