Wednesday, 16 December 2015

Password protected PDF using iTextSharp

        private void ProtectPDF()
        {
            string InputFile = @"~\NewFolder1\Worksheet.pdf";
            string OutputFile = @"~\NewFolder1\Confidential.pdf";

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

No comments:

Post a Comment