Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
there are number of pdf files in a folder i want to set password to all these pdf files.password should be employee-id provided in that pdf file.if any related code anybody knows please provide it with proper dll and namespaces.

What I have tried:

please provide me proper code with namespace and assembly dll files.
Posted
Updated 15-Nov-17 0:24am
v7
Comments
Mehdi Gholam 15-Nov-17 4:54am    
Protect how? form what?
Member 13460675 15-Nov-17 5:18am    
set password to all pdf files in a folder.
Karthik_Mahalingam 15-Nov-17 5:05am    
Use Improve question to add more info to the question.
Member 13460675 15-Nov-17 5:54am    
karthik..do you understand my question now?
Karthik_Mahalingam 15-Nov-17 6:35am    
check the solution

1 solution

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
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900