Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to encrypt the pdf file in such a manner that when user tries to open the pdf file through application, user should be able to view the document without entering the password (i.e., the password should be passed programmatically). Also, when user tries to download the same file from the browser and opens the downloaded file, it should ask the encrypted password to open the file.

What I have tried:

I have tried to use iTextSharp and encrypt the pdf, but it will encrypt the password while viewing and downloading. but I need the password protection only when I download the pdf from browser and not when I view in browser.
Posted
Updated 1-Nov-17 23:43pm

1 solution

You can't do that.
A PDF file is either password protected - in which case the user needs to enter the password - or it isn't: there is no "optional password" as the password acts as an encryption key to protect the content.

When you pass a PDF file to the browser, you have no real control over what happens to it: the user can save of view it as they please. If you said to yourself "oh, he's viewing" and provided a password-free version of the document, it could be saved and viewed in any PDF viewer without the password later.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900