Click or drag to resize

PdfEncryptionDetails Class

Contains details for encrypting and access permissions for a PDF document.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentPdfEncryptionDetails

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax
public sealed class PdfEncryptionDetails

The PdfEncryptionDetails type exposes the following members.

Properties
 NameDescription
Public propertyCode exampleEncryptionAlgorithm Specifies the encryption algorithm to use.
Public propertyCode exampleOwnerPassword Specifies the owner password for the encrypted PDF document.
Public propertyCode examplePermissions Specifies the operations that are allowed to a user on an encrypted PDF document. The default value is DisallowAll.
Public propertyCode exampleUserPassword Specifies the user password required for opening the encrypted PDF document.
Top
Example

See Developer Guide: Create and secure a PDF document by password

Create and secure a PDF document by password. Also set the permissions for the document using C#
using System;
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using System.IO;
using System.Linq;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 100-day key here:   
            // https://sautinsoft.com/start-for-free/

            SecureDocument();
        }

        /// <summary>
        /// Create and secure a PDF document by password. Also set the permissions for the document.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/security-options-net-csharp-vb.php
        /// </remarks>
        public static void SecureDocument()
        {
            string filePath = @"ProtectedDocument.pdf";

            DocumentCore dc = new DocumentCore();

            // Let's create a simple document.
            dc.Content.End.Insert("Hello World!!!", new CharacterFormat() { FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange });

            PdfSaveOptions so = new PdfSaveOptions();
            // Password Protection
            so.EncryptionDetails.UserPassword = "12345";
            // EncryptionAlgorithm
            so.EncryptionDetails.EncryptionAlgorithm = PdfEncryptionAlgorithm.RC4_128;
            //Permissions: Content Copying, Commenting, Printing, Changing the Document, filing of form fildes etc
            //Printing: Allowed
            so.EncryptionDetails.Permissions = PdfPermissions.Printing;

            // Save a document as the PDF file with Security Options.
            dc.Save(filePath, so);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
Create and secure a PDF document by password. Also set the permissions for the document using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        SecureDocument()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Create and secure a PDF document by password. Also set the permissions for the document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/security-options-net-csharp-vb.php
    ''' </remarks>
    Sub SecureDocument()
        Dim filePath As String = "ProtectedDocument.pdf"

        Dim dc As New DocumentCore()

        ' Let's create a simple document.
        dc.Content.End.Insert("Hello World!!!", New CharacterFormat() With {
                .FontName = "Verdana",
                .Size = 65.5F,
                .FontColor = Color.Orange
            })

        Dim so As New PdfSaveOptions()
        ' Password Protection
        so.EncryptionDetails.UserPassword = "12345"
        ' EncryptionAlgorithm
        so.EncryptionDetails.EncryptionAlgorithm = PdfEncryptionAlgorithm.RC4_128
        'Permissions: Content Copying, Commenting, Printing, Changing the Document, filing of form fildes etc
        'Printing: Allowed
        so.EncryptionDetails.Permissions = PdfPermissions.Printing

        ' Save a document as the PDF file with Security Options.
        dc.Save(filePath, so)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub
End Module
See Also