I use the following code :
string WorkingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string InputFile = Path.Combine(WorkingFolder, "PSNOs.pdf");
string OutputFile = Path.Combine(WorkingFolder, "PSNOs_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, null, "secret", PdfWriter.ALLOW_SCREENREADERS);
}
}
But it is creating another file and adding password to the output file.
But I don’t want to create two files like the above. I want to give the password for the input file PSNOs.pdf with out creating the other file.
It must be done this way unfortunately.
I would suggest you: