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!
Encrypt a pdf file (Delphi) |
Post Reply |
Author | |
Amelie
Beginner Joined: 10 Nov 17 Location: France Status: Offline Points: 13 |
Post Options
Thanks(0)
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 |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(1)
|
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)!
|
|
Amelie
Beginner Joined: 10 Nov 17 Location: France Status: Offline Points: 13 |
Post Options
Thanks(0)
|
Hi,
Thanks for your help. It works well ! I use version 11.13. @ tfrost : thanks for your advices Have a good day Amélie
|
|
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