Assigning User Password and Owner Passsword

Hy

1. Can some one help me to assign both password in C# code

2. When I use following code for change password, Its throwing "Bad Password" error

fileSecurity.EncryptFile("userpwd", "ownpwd", DocumentPrivilege.Copy, false);

Thanks

Hi,

Thank you for considering Aspose!

It's a known issue for "Bad Password error" in PdfFileSecurity.EncryptFile(). The issue is resolved now, and that fix will be included in our next publishing. As a workaround, please use the 128 bits encryption instead of 40 bits, say , replace the 'false' with 'true'.

Thanks,

Hi,

The code that you using is correct but it isn't working. I have logged this as PDFKITNET-4077 in our issue tracking system. We will try our best to resolve this as soon as possible.

Thanks.

Thanks

But my first problem still remains

I want to assign Document Open Password to the output pdf file

How can I assign?

Should I use EncryptFile Method for this? Or any kind of facility(Setting Password) is there?

Hi,

Setting the password for opening pdf file is not currently supported. I will discuss this with the developers to see if we can support it in short time.

Thanks.

After discussion with developers we found this feature is supported. You can simply set the password of the user and owner (using
PdfFileSecurity.EncrpFile), then the pdf cannot be opened without the password.

Here is the example code:

PdfFileSecurity security = new PdfFileSecurity(“d:/test/test.pdf”,“d:/test/testout.pdf”);
security.EncryptFile(“abc”,“123”,PdfPrivilege.AllowAll,true);

Hi This code is helpful, but I want to set only document open password, I don't want to encrypt file. Is this possible ?

I have tried below code with Encrypted Method but it also takes the permission password as true

PdfFileSecurity security = new PdfFileSecurity("d:/test/test.pdf","d:/test/testout.pdf");
security.EncryptFile("abc","",PdfPrivilege.AllowAll,true);

Hi,

The file is encrypted when you set any password, in disregard of which type of password is chosen.

And if what you want is that the encrypted file should be opened with password, you should set user's password (as you did in above codes, and the owner's password could be omitted).

Thanks,

Hi

So I encrypt file with only Document Open Password as per belowed code

sec.EncryptFile("OpenPW", "", DocumentPrivilege.AllowAll, true);

But still after excuting code the output pdf document is showing that both document open and permission password are there as below

I have opened followed window

File-> Properties-->Security --> Show Details -->

Document Open Password - Yes

Permission Password - Yes

Can you please tell me why it still shoes yes?

When I tried DocOpen Pw - "", PermissionPW - "PerPw" :- It showes Document Open Password - No , and Permisison Password - Yes ,

So here it is working, but for 1st part its not working

Thanks

Hi,

It is not logical to have a open password and not have permissions password because then some one could simple remove the open password. That is why when a open password is set a permission password is also set.

Thanks.