且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#窗口或Web应用程序保护文件夹中的多个pdf文件?

更新时间:2022-11-04 19:49:39

参考此示例并类似地迭代文件夹中的所有文件,并根据您的逻辑分配密码。

refer this example and similarly iterate for all the files in the folder and assign the password based on your logic.
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Security;

namespace CP
{ 
    class POCProgram
    { 
        static void Main(string[] args)
        {   
            string path =@"D:\Projects\CPTemp\CPTemp\abc.pdf";
            PdfDocument document = PdfReader.Open(path);
            PdfSecuritySettings securitySettings = document.SecuritySettings; 
            securitySettings.UserPassword = "MyPassword"; 
            document.Save(path);
        } 
    }
}





PDFSharp NuGet [ ^ ],

参考此视频,了解如何使用Visual Studio的软件包管理器控制台安装Nuget软件包 [ ^ ]

请参考目录。 GetFiles方法(字符串)(System.IO) [ ^ ]读取文件夹中的所有文件



Install the Package from PDFSharp NuGet[^],
refer this video to know how to Install Nuget package using Package Manager Console of Visual Studio [^]
refer Directory.GetFiles Method (String) (System.IO)[^] to read all the files from a folder