Class PdfSecurity

Informação

Representa o componente Documentize.PdfSecurity. Usado para Criptografar, Descriptografar, Assinar e Sanitizar documentos PDF.

public static class PdfSecurity

Inheritance

objectPdfSecurity

Inherited Members

Métodos

Descriptografar(DecryptOptions)

Descriptografa documento PDF.

public static ResultContainer Decrypt(DecryptOptions options)

Parâmetros

  • options DecryptOptions: Um objeto de opções contendo instruções para a operação.

Retorna

ResultContainer : Um objeto contendo o resultado da operação.

Exemplos

O exemplo demonstra como Descriptografar um documento PDF.

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

Exceções

ArgumentException

Se as opções não estiverem definidas.

Criptografar(EncryptOptions)

Criptografa documento PDF.

public static ResultContainer Encrypt(EncryptOptions options)

Parâmetros

  • options EncryptOptions: Um objeto de opções contendo instruções para a operação.

Retorna

ResultContainer : Um objeto contendo o resultado da operação.

Exemplos

O exemplo demonstra como Criptografar um documento PDF.

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

Exceções

ArgumentException

Se as opções não estiverem definidas.

Sanitizar(SanitizeOptions)

Sanitiza dados ocultos de um documento PDF, garantindo que informações sensíveis ou desnecessárias, como metadados, anotações, JavaScripts ou conteúdo privado, sejam removidas ou transformadas.

public static ResultContainer Sanitize(SanitizeOptions options)

Parâmetros

  • options SanitizeOptions: Um objeto de opções contendo instruções para a operação.

Retorna

ResultContainer : Um objeto contendo o resultado da operação.

Exemplos

O exemplo demonstra como Sanitizar um documento PDF.

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

O exemplo demonstra como Sanitizar PDF de stream para 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);

O exemplo demonstra como Sanitizar PDF de arquivo para 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);

O exemplo demonstra como Sanitizar PDF de arquivo para stream com definição manual das propriedades de entrada e saída.

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

O exemplo demonstra como Sanitizar PDF sem remover Metadados.

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

O exemplo demonstra como Sanitizar PDF sem remover Anexos.

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

O exemplo demonstra como Sanitizar PDF convertendo todas as páginas em imagens e definindo DPI do resultado.

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

O exemplo demonstra como Sanitizar PDF sem remover JavaScripts e Ações.

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

O exemplo demonstra como Sanitizar um arquivo PDF da forma mais curta possível.

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

Exceções

ArgumentException

Se as opções não estiverem definidas.

Assinar(SignOptions)

Assina documento PDF com assinatura digital.

public static ResultContainer Sign(SignOptions options)

Parâmetros

  • options SignOptions: Um objeto de opções contendo instruções para a operação.

Retorna

ResultContainer : Um objeto contendo o resultado da operação.

Exemplos

O exemplo demonstra como Assinar um documento PDF.

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

O exemplo demonstra como Assinar um documento PDF com Stream do Arquivo PFX.

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

O exemplo demonstra como Assinar um documento PDF com assinatura invisível.

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

O exemplo demonstra como Assinar um documento PDF com opções extras.

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

O exemplo demonstra como Assinar um documento PDF com 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);

Exceções

ArgumentException

Se as opções não estiverem definidas.

Namespace: Documentize Assembly: Documentize.dll

 Português