XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Password: Open Document
  |  
Home ›› XDoc.PDF ›› C# PDF: Edit PDF Password

C#.NET PDF SDK - Apply PDF Password with Access Permission Using C#.NET


Help C# Developers to Improve the Security of Your PDF Document by Setting Password in C# .NET Application



Look for HTML5 PDF Editor?

EdgePDF: ASP.NET PDF Editor is the best HTML5 PDF Editor and ASP.NET PDF Viewer based on XDoc.PDF, JQuery, HTML5. It supports ASP.NET MVC and WebForms projects.


Best .NET PDF document manipulation SDK library for PDF document protecting in Visual C# .NET framework project


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


A professional PDF encryption and decryption control able to be integrated in C#.NET WinForm and ASP.NET WebForm application


Able to perform PDF file password adding, deleting and changing in Visual Studio .NET project use C# source code in .NET class


Allow to decrypt PDF password and open a password protected document in C#.NET framework


Support to add password to PDF document online or in C#.NET WinForms for PDF file protection


Able to create a password protected PDF contains file permission limitation


An advanced PDF password remover component can help users unlock PDF file without password


Able to change password on adobe PDF document in C#.NET


To help protect your PDF document in C# project, XDoc.PDF provides some PDF security settings. On this page, we will talk about how to achieve this via password. In general, you can do following manipulations.






C# add password to pdf document


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




        #region add password to pdf document
        internal static void addPassword()
        {
            // Define input and output files path.
            String inputFilePath = @"C:\demo_without_pw.pdf";
            String outputFilePath = @"C:\demo_with_pw.pdf";

            // Set passwords for user and owner.
            String userPassword = "you";
            String ownerPassword = "me";

            // Create password setting.
            PasswordSetting setting = new PasswordSetting(userPassword, ownerPassword);

            // Add password to plain PDF file and output a new file.
            int errorCode = PDFDocument.AddPassword(inputFilePath, outputFilePath, setting);
            if (errorCode == 0)
            {
                Console.WriteLine("Success");
            }
            else
            {
                Console.WriteLine("Failed");
            }

        }
        #endregion




C# update password to pdf document





        #region update password to pdf document
        internal static void updatePassword()
        {
            // Define input file path.
            String intputFilePath = @"C:\demo.pdf";

            // Set PDF passwords.
            String userPassword = "you";
            String newUserPassword = "fill";
            String newOwnerPassword = "watch";

            // Create setting for the new password.
            PasswordSetting setting = new PasswordSetting(newUserPassword, newOwnerPassword);

            // Change password for an encrypted PDF file.
            int errorCode = PDFDocument.ChangePassword(intputFilePath, userPassword, setting);
            if (errorCode == 0)
            {
                Console.WriteLine("Success");
            }
            else
            {
                Console.WriteLine("Failed");
            }

        }
        #endregion




C# remove password to pdf document





        #region remove password from pdf document
        internal static void removePassword()
        {
            // Define input file path.
            String intputFilePath = @"C:\demo.pdf";

            // Set user password.
            String userPassword = @"you";

            // Remove password in the file.
            int errorCode = PDFDocument.RemovePassword(intputFilePath, userPassword);
            if (errorCode == 0) 
                Console.WriteLine("Success");
            else 
                Console.WriteLine("Failed");

        }
        #endregion




.NET Class Namespace Required



In order to run the sample code, the following steps would be necessary.


Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;