Add a password to a PDF, allowing no one to even view the file unless they have the password.
PDF is used for both business and personal use. It comes with different features and functions, including Graphics, page order, Carpool working, etc. which are quite handy in many fields. However, with such wide adoption Privacy issues also arise, requiring proper protection.
XsPDF lets you encrypt your PDF documents, adding password protection for restricting permissions, or entirely locking the PDF from any modifications or even require a password to view the document.
In this C# .NET tutorial, learn how to protect PDF by using the Protect tool to keep your information safe. Keep others from copying, printing and editing the information in your PDF documents with just a password.
// Open an existing document. PdfDocument document = PdfReader.Open("file1.pdf"); PdfSecuritySettings securitySettings = document.SecuritySettings; // Add user password and owner password securitySettings.UserPassword = "user password"; securitySettings.OwnerPassword = "owner password"; // Set passwords security level securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted128Bit; // Restrict permission rights. Disallow all the editing rights. securitySettings.PermitAccessibilityExtractContent = false; securitySettings.PermitAnnotations = false; securitySettings.PermitAssembleDocument = false; securitySettings.PermitExtractContent = false; securitySettings.PermitFormsFill = false; securitySettings.PermitFullQualityPrint = false; securitySettings.PermitModifyDocument = false; securitySettings.PermitPrint = false; // Save the document... document.Save("Encrypt.pdf");
While the PDF file has a user password, the Adobe Reader will prompt for a password. If you want to show the PDF document directly, you can set an owner password instead of a user password. There will be no prompt when Adobe Reader opens the file, but editing will be prevented.
More PDF tutorial
- Create Code-128 to PDF in C#
- Modify PDF chart color in C#.NET
- How to decrease Acrobat PDF in Azure cloud service using .NET C#
- 2D Aztec Code making to PDF in .NET Visual C# is quite easy and quick using XsPDF barcode Control for .NET
- Creating QRCode to PDF page using .NET Visual C# and XsPDF Library
- .NET C# tutorial for generation PDF file from jpeg/jpg
- .NET C# online guide for creation Code 3 of 9 to PDF page
- C#.NET demo for creating an exsited page to PDF file
- Visual Studio .NET framework online sample for breaking multi-page PDF into two or more separate PDF documents
- 2D DataMatrix generation to PDF in .NET Visual C# is quite easy and quick using XsPDF barcode source code for .NET
- Draw Area graphs to PDF in Visual C#
- .NET Visual C# online sample for reading image from PDF page
- How to use XsPDF Chart Toolkit for .NET to make Bar chart on PDF page in .NET
- Decrypt PDF document in Visual Studio .NET framework
- Creating PDF document using Visual Studio .NET framework and XsPDF source code