Read Protected Pdf using Password [Resolved]

Posted by Ramumohan under C# on 3/1/2016 | Points: 10 | Views : 1494 | Status : [Member] | Replies : 3
HI All,

I have protected PDF Files in one folder i want to read that PDF by providing password automatically through code without any user manually input.Please I request you to help me out to solve this issue(when i am trying to do i am getting Bad user Password Error),
Thanks in advance

I am using this code to execute

string WorkingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string InputFile = Path.Combine(WorkingFolder, "zr1VSB.pdf");
string OutputFile = Path.Combine(WorkingFolder, "zr1VSB_enc.pdf");

using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfReader reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, "zr1VSB", "secret", PdfWriter.ALLOW_SCREENREADERS);
}
}




Responses

Posted by: A2H on: 3/1/2016 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
If you are ok with third party tools then You might want to try Docotic.Pdf library for the task
http://bitmiracle.com/pdf-library/
You can find sample code to open pdf by providing pass in below link
http://stackoverflow.com/questions/10906422/how-can-a-password-protected-pdf-file-be-opened-programmatically

Thanks,
A2H
My Blog

Ramumohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ramumohan on: 3/1/2016 [Member] Starter | Points: 25

Up
0
Down
HI,

Thanks for your valuable reply as per my requirement i should not use third party tools i need to complete the task with .Net code only

Thanks & Regards
Ram

Ramumohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Professionaluser on: 3/2/2016 [Member] [MVP] Bronze | Points: 25

Up
0
Down
there is one opensource library to read protected PDF files

http://stackoverflow.com/questions/11645941/how-to-programmatically-enter-password-on-encrypted-pdf

Ramumohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response