การสำเนาไฟล์ PDF และต้องใส่รหัสผ่านในการเปิดไฟล์ด้วย iTextSharp

ติดตั้ง

PM> Install-Package iTextSharp -Version 5.5.13.1
using iTextSharp.text.pdf;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string ipFilename = "original.pdf";
            string opFilename = "encrypted.pdf";
            string password = @"21042020";

            using (PdfReader reader = new PdfReader(ipFilename))
            using (FileStream fs = new FileStream(opFilename, FileMode.Create, FileAccess.Write, FileShare.None))

            using (PdfStamper stamper = new PdfStamper(reader, fs))
            {
                stamper.SetEncryption(PdfWriter.STRENGTH40BITS, password, null, PdfWriter.ALLOW_COPY);
            }
        }
    }
}