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);
}
}
}
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