C# Encrypt PDF Files
PDF files have become as commonplace as MS office files. As one of the most important document files, PDF owns a huge amount of users. Sometimes sensitive information is on these PDF files and one needs to be able to protect the files from unauthorized users. Gain a sense of security. PDF enables users to set up different passwords for specific functions. PDF security program adds both passwords user password and owner password. And here in this article, you will know a solution of how to use C# encrypt PDF files.
How to Use C# Encrypt PDF Files
Through C#, PDF developers can encrypt PDF files without Adobe Acrobat installed on system. Spire.PDF, as a professional .NET/Silverlight PDF component can help users easily use C# to encrypt PDF files. Download Spire.PDF, make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the simple guide below to encrypt a PDF file with C# code.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project.
using System;
using Spire.Pdf;
namespace encryptPDF
{
class Program
{
static void Main(string[] args)
{
}
}
}
Step 2 Create PDF File
Spire.PDF enables developers create PDF document. Here we can create a PDF file and then encrypt by setting password.
//Create a pdf document.
PdfDocument doc = new PdfDocument();
// Create one page
PdfPageBase page = doc.Pages.Add();
//Draw the page
DrawPage(page);
Step 3 C# Encrypt PDF Files
By using Spire.PDF, we can use C# to encrypt PDF files by setting PDF own password and user password.
//encrypt
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "e-iceblue";
doc.Security.UserPassword = "test";
doc.Security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FileFields;
Step 4 Save and Preview
Save the file as PDF format and launch PDF file after finish the project.
//Save pdf file.
doc.SaveToFile("Encryption.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("Encryption.pdf");
How to Use C# Encrypt PDF Files
Through C#, PDF developers can encrypt PDF files without Adobe Acrobat installed on system. Spire.PDF, as a professional .NET/Silverlight PDF component can help users easily use C# to encrypt PDF files. Download Spire.PDF, make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the simple guide below to encrypt a PDF file with C# code.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project.
using System;
using Spire.Pdf;
namespace encryptPDF
{
class Program
{
static void Main(string[] args)
{
}
}
}
Step 2 Create PDF File
Spire.PDF enables developers create PDF document. Here we can create a PDF file and then encrypt by setting password.
//Create a pdf document.
PdfDocument doc = new PdfDocument();
// Create one page
PdfPageBase page = doc.Pages.Add();
//Draw the page
DrawPage(page);
Step 3 C# Encrypt PDF Files
By using Spire.PDF, we can use C# to encrypt PDF files by setting PDF own password and user password.
//encrypt
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "e-iceblue";
doc.Security.UserPassword = "test";
doc.Security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FileFields;
Step 4 Save and Preview
Save the file as PDF format and launch PDF file after finish the project.
//Save pdf file.
doc.SaveToFile("Encryption.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("Encryption.pdf");
More about Spire.PDF
Spire.PDF can not only help developers encrypt PDF files via C#/VB.NET. As a PDF document creation component, Spire.PDF enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…
Spire.PDF can not only help developers encrypt PDF files via C#/VB.NET. As a PDF document creation component, Spire.PDF enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…