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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > General Discussion
  New Posts New Posts RSS Feed - Encrypt a pdf file (Delphi)
  FAQ FAQ  Forum Search   Register Register  Login Login

Encrypt a pdf file (Delphi)

 Post Reply Post Reply
Author
Message
Amelie View Drop Down
Beginner
Beginner


Joined: 10 Nov 17
Location: France
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote Amelie Quote  Post ReplyReply Direct Link To This Post Topic: Encrypt a pdf file (Delphi)
    Posted: 05 Dec 17 at 5:39PM
Hello!

how to encrypt a pdf file (Delphi) please with "Quick PDF Library" ?
I tried the following code, but it does not encrypt the file:

var
  CanProceed: Boolean;
begin

CanProceed := False;
  if dlgOpen.Execute then
  begin
    ViewPrintQP := TDebenuPDFLibrary.Create;
    if ViewPrintQP.UnlockKey(edtLicenseKey.Text) = 1 then
    begin
      if ViewPrintQP.LoadFromFile(dlgOpen.FileName, '') = 1 then
      begin
        CanProceed := True;
      end else
        MessageDlg('The PDF could not be opened.', mtError, [mbOK], 0);
    end else
      MessageDlg('The license key is invalid or has expired.', mtError, [mbOK], 0);
  end;

ViewPrintQP.Encrypt(dlgOpen.FileName , '' , 'Owner' , 'User' , 1 , 1);

ViewPrintQP.SaveToFile('E:\encrypted_doc.pdf');


it saves the file but it is not encrypted and it is not protected by password.

how to solve this problem please?

Thank you.

Best regards.
Amelie


Edited by Amelie - 05 Dec 17 at 5:46PM
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 05 Dec 17 at 9:31PM
Hi Amelie,

here you can read about the encrypt-function (only four parameters are available):
http://www.debenu.com/docs/pdf_library_reference/Encrypt.php
And here you can read about how to generate the fourth parameter:
http://www.debenu.com/docs/pdf_library_reference/EncodePermissions.php
Sample for Encrypt and EncodePermission:
// . . .
var
p5, p6, p7, p8, p9, p10, p11, p12, perm : LongInt;
perm := ViewPrintQP.EncodePermissions(p6, p7, p8, p10, p9, p11, p12, 0);
ViewPrintQP.Encrypt('Owner' , 'User' , 1 , perm);
// . . .
There's no need to insert dlgOpen.FileName into the encrypt-function 'cause the file is already known with the LoadFromFile.

To make it clean you should check first, if the file is already encrypted and do a decrypt.
This you can do after LoadFromFile.
Here's a sample:
// . . .
If ( ViewPrintQP.EncryptionStatus > 0 ) Then
     ViewPrintQP.Decrypt;
// . . .

Wish you more luck with the next try ;-)

Cheers,
Ingo

Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (1) Thanks(1)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 05 Dec 17 at 9:32PM
Please check again the documentation for Encrypt.  The parameters for Delphi should be Owner, User, Strength, Permissions.  The filename should not be there, and the final '1' should be replaced by a value returned from an earlier call to EncodePermissions.

Then, check the result code from Encrypt before you save the file.  If you get a 0, call LastErrorCode to get more information.  Alternatively, if all you want to do is encrypt the file, you can use EncryptFile.

I am sure that users here will be happy to help you if we have a bit more detail (including the library version you are using)!
Back to Top
Amelie View Drop Down
Beginner
Beginner


Joined: 10 Nov 17
Location: France
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote Amelie Quote  Post ReplyReply Direct Link To This Post Posted: 06 Dec 17 at 8:25AM
Hi,

Thanks for your help. It works well !
 I use version 11.13.

tfrost : thanks for your advices

Have a good day

Amélie
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store