• Home
  • Product-Life
  • PDF
  • Excel
  • Word
  • My Music Box
It's a long road...

PDF Focus .Net

A standalone C# library to convert PDF to Word and Images. Independent and doesn't require Adobe Actobat or any other software.

Learn more

C# PDF - Encrypt PDF Files

3/20/2012

0 Comments

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

Picture
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…

0 Comments



Leave a Reply.

    Categories

    全部
    Add Image Watermark
    Add Pdf Attachment
    Add Text Watermark
    Create Barcode
    Create Pdf From Excel
    Create Pdf From Html
    Create Pdf From Image
    Create Pdf From Text
    Create Pdf From Word
    Datatable To Pdf
    Encrypt Pdf Files
    Extract Pdf Image
    Extract Pdf Text
    Html To Pdf Conversion
    Insert Pdf Bookmark
    Insert Pdf Header
    Merge Pdf Files
    Split Pdf File

    RSS Feed

    Recommend Blog:


    Blu-ray/DVD Backup
    Office Tricks
    No.1 Software Pick
    提交

Powered by
✕