PDF security and encryption options.
[SerializableAttribute()]
public class PDFSecurityOptions
public class PDFSecurityOptions
[SerializableAttribute()]
public ref class PDFSecurityOptions
class PDFSecurityOptions:
The PDFSecurityOptions class is used as the type for the SecurityOptions and used to read and write the security and encryption options to use with PDF files.
When reading PDF documents, PDFDocument.SecurityOptions will always be populated automatically when the PDFDocument object is initialized.
When writing PDF documents, the following methods of the PDFFile class will use the security options set in PDFFile.SecurityOptions when updating or created a PDF file:
If the value of PDFFile.SecurityOptions is null, then the PDFFile will not encrypt the result PDF file.
There are two different types of passwords to protect different aspects of a PDF file with a password:
By using a user password set in UserPassword external viewers such as Adobe Acrobat will ask the user for the same password when opening the file for viewing. If the correct password is supplied, then the PDF is opened for viewing.
By using an owner password set in OwnerPassword external viewers such as Adobe Acrobat will disallow certain operations on the PDF file such as printing or editing. These operations can be re-enabled by editing the PDF's security options and supplying the owner password.
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));
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document