Class PdfSecurity

Info

Represents Documentize.PdfSecurity component. Used to Encrypt, Decrypt, Sign, Sanitize PDF documents.

public static class PdfSecurity

Inheritance

objectPdfSecurity

Inherited Members

Methods

Decrypt(DecryptOptions)

Decrypt PDF document.

public static ResultContainer Decrypt(DecryptOptions options)

Parameters

  • options DecryptOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Examples

The example demonstrates how to Decrypt PDF document.

// Create DecryptOptions object to set instructions
var options = new DecryptOptions("123456");
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfSecurity.Decrypt(options);

Exceptions

ArgumentException

If options not set.

Encrypt(EncryptOptions)

Encrypt PDF document.

public static ResultContainer Encrypt(EncryptOptions options)

Parameters

  • options EncryptOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Examples

The example demonstrates how to Encrypt PDF document.

// Create EncryptOptions object to set instructions
var options = new EncryptOptions("123456", "qwerty");
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfSecurity.Encrypt(options);

Exceptions

ArgumentException

If options not set.

Sanitize(SanitizeOptions)

Sanitize hidden data from a PDF document, ensuring that sensitive or unnecessary information such as metadata, annotations, JavaScripts, or private content is removed or transformed.

public static ResultContainer Sanitize(SanitizeOptions options)

Parameters

  • options SanitizeOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Examples

The example demonstrates how to Sanitize PDF document.

// Create SanitizeOptions object to set input and output files
var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF from stream to stream.

// Prepare input and output streams
using var inputStream = File.OpenRead("path_to_your_pdf_file.pdf");
using var outputStream = new MemoryStream();
// Create SanitizeOptions object to set input and output streams
var options = new SanitizeOptions(inputStream, outputStream);
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF from file to stream.

// Prepare output stream
using var outputStream = new MemoryStream();
// Create SanitizeOptions object to set input and output streams
var options = new SanitizeOptions("path_to_your_pdf_file.pdf", outputStream);
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF from file to stream with manual setting input and output properties.

// Create SanitizeOptions object
var options = new SanitizeOptions();
//Set Input file
options.Input = new FileData("path_to_your_pdf_file.pdf");
//Set Output file
options.Output = new FileData("path_to_result_pdf_file.pdf");
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF without removing Metadata.

// Create SanitizeOptions object to set input and output files
var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
options.RemoveMetadata = false;
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF without removing Attachments.

// Create SanitizeOptions object to set input and output files
var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
options.RemoveAttachments = false;
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF with converting all pages to images and set result dpi.

// Create SanitizeOptions object to set input and output files
var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
// Turn on conversion and set dpi
options.ConvertPagesToImages = true;
options.ImageDpi = 200;
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF without removing JavaScripts and Actions.

// Create SanitizeOptions object to set input and output files
var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
options.RemoveJavaScriptsAndActions = false;
// Perform the process
PdfSecurity.Sanitize(options);

The example demonstrates how to Sanitize PDF file in the shortest possible style.

// Perform the process
PdfSecurity.Sanitize(new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf"));

Exceptions

ArgumentException

If options not set.

Sign(SignOptions)

Sign PDF document by digital signature.

public static ResultContainer Sign(SignOptions options)

Parameters

  • options SignOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Examples

The example demonstrates how to Sign PDF document.

// Create SignOptions object to set instructions
var options = new SignOptions("path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfSecurity.Sign(options);

The example demonstrates how to Sign PDF document with Stream of PFX File.

using var pfxStream = File.OpenRead(@"path_to_your_pfx_file.pfx");
var options = new SignOptions(pfxStream, "password_of_your_pfx_file");
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfSecurity.Sign(options);

The example demonstrates how to Sign PDF document with invisible signature.

var options = new SignOptions("path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Configure invisible signature
signOptions.Visible = false;
// Perform the process
PdfSecurity.Sign(options);

The example demonstrates how to Sign PDF document with extra options.

// Create SignOptions object to set instructions
var options = new SignOptions("path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Optional parameters
options.Reason = "my Reason";
options.Contact = "my Contact";
options.Location = "my Location";
options.PageNumber = 3;
// Perform the process
PdfSecurity.Sign(options);

The example demonstrates how Sign PDF document with Timestamp.

// Create SignOptions object to set instructions
var options = new SignOptions("path_to_your_pfx_file.pfx", "password_for_your_pfx_file");
options.TimestampOptions = new TimestampOptions("server_url");
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfSecurity.Sign(options);

Exceptions

ArgumentException

If options not set.

Namespace: Documentize Assembly: Documentize.dll

 English