←Select platform

EncryptionMode Property

Summary

Indicates the encryption mode to use when updating or creating a PDF document.

Syntax

C#
C++/CLI
Java
Python
public PDFEncryptionMode EncryptionMode { get; set; } 
public PDFEncryptionMode getEncryptionMode(); 
public void setEncryptionMode( 
   PDFEncryptionMode pDFEncryptionMode 
); 
public: 
property PDFEncryptionMode EncryptionMode { 
   PDFEncryptionMode get(); 
   void set (    PDFEncryptionMode ); 
} 
EncryptionMode # get and set (PDFSecurityOptions) 

Property Value

A PDFEncryptionMode enumeration member that specifies the encryption mode to use when updating or creating a PDF document. The default value is PDFEncryptionMode.RC40Bit.

Remarks

PDF encryption mode specifies the key size used to encrypt the PDF file when setting the UserPassword.

The encryption mode used when setting a UserPassword property, dictates whether to restrict high-quality printing. To enable high-quality printing, set PDFEncryptionMode to PDFEncryptionMode.RC128Bit encryption mode. Conversely, PDFEncryptionMode set to PDFEncryptionMode.RC40Bit disables high-quality printing. For further details about high-quality printing, refer to HighQualityPrintEnabled .

Example

C#
Java
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
 
 
/// This example will encrypt a PDF file with both a user password and an owner password and restrict printing. 
 
public void PDFFileSecurityOptionsExample() 
{ 
   string sourceFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
   string destinationFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_EncryptedNoPrint.pdf"); 
 
   PDFFile pdfFile = new PDFFile(sourceFileName); 
 
   // Set the security options 
   pdfFile.SecurityOptions = new PDFSecurityOptions(); 
   pdfFile.SecurityOptions.UserPassword = "LEAD"; 
   pdfFile.SecurityOptions.OwnerPassword = "LEAD_SECRET"; 
   pdfFile.SecurityOptions.PrintEnabled = false; 
   pdfFile.SecurityOptions.HighQualityPrintEnabled = false; 
   pdfFile.SecurityOptions.EncryptionMode = PDFEncryptionMode.RC128Bit; 
 
   // Encrypt the file by saving it to the destination file 
   pdfFile.Convert(1, -1, destinationFileName); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.ByteArrayInputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.FileReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.nio.file.StandardCopyOption; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 
import java.util.Scanner; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.pdf.*; 
 
 
public void pdfFileSecurityOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String sourceFileName = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
   String destinationFileName = combine(LEAD_VARS_IMAGES_DIR, "LEAD_EncryptedNoPrint.pdf"); 
   PDFFile pdfFile = new PDFFile(sourceFileName); 
 
   // Set the security options 
   pdfFile.setSecurityOptions(new PDFSecurityOptions()); 
   pdfFile.getSecurityOptions().setUserPassword("LEAD"); 
   pdfFile.getSecurityOptions().setOwnerPassword("LEAD_SECRET"); 
   pdfFile.getSecurityOptions().setPrintEnabled(false); 
   pdfFile.getSecurityOptions().setHighQualityPrintEnabled(false); 
   pdfFile.getSecurityOptions().setEncryptionMode(PDFEncryptionMode.RC128_BIT); 
 
   // Encrypt the file by saving it to the destination file 
   pdfFile.convert(1, -1, destinationFileName); 
   assertTrue("Check for encryption", PDFFile.isEncrypted(destinationFileName)); 
 
} 

Requirements

Target Platforms

See Also

PDFSecurityOptions Class

PDFSecurityOptions Members

UserPassword

OwnerPassword

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.