Class PdfSecurity

Informação

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

public static class PdfSecurity

Herança

object ← PdfSecurity

Membros Herdados

Métodos

Decrypt(DecryptOptions)

Descriptografar documento PDF.

public static ResultContainer Decrypt(DecryptOptions options)

Parâmetros

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

Retorno

ResultContainer : Um objeto que contém 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 forem definidas.

Encrypt(EncryptOptions)

Criptografar documento PDF.

public static ResultContainer Encrypt(EncryptOptions options)

Parâmetros

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

Retorno

ResultContainer : Um objeto que contém 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 forem definidas.

Sanitize(SanitizeOptions)

Sanitizar dados ocultos de um documento PDF, garantindo que informações sensíveis ou desnecessárias como metadados, anexos, anotações, JavaScripts, formulários, camadas, índice de busca 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.

Retorno

ResultContainer : Um objeto que contém 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 um 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 um PDF de arquivo para stream.

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

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

// Prepare output stream
using var outputStream = new MemoryStream();
// Create SanitizeOptions object
var options = new SanitizeOptions();
//Set Input file
options.Input = new FileData("path_to_your_pdf_file.pdf");
//Set Output stream
options.Output = new StreamData(outputStream);
// Perform the process
PdfSecurity.Sanitize(options);

O exemplo demonstra como Sanitizar um 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 um 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 um PDF convertendo todas as páginas em imagens e definindo DPI de 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 um 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 maneira mais curta possível.

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 forem definidas.

Sign(SignOptions)

Assinar 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.

Retorno

ResultContainer : Um objeto que contém 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_pdf_file.pdf", "path_to_result_pdf_file.pdf", "path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
// Perform the process
PdfSecurity.Sign(options);

O exemplo demonstra como Assinar um documento PDF usando streams.

// Prepare streams
using var pdfStreamInput = File.OpenRead(@"path_to_your_pdf_file.pdf");
using var pfxStreamInput = File.OpenRead(@"path_to_your_pfx_file.pfx");
using var pdfStreamOutput = new MemoryStream();
// Create SignOptions object to set instructions
var options = new SignOptions(pdfStreamInput, pdfStreamOutput, pfxStreamInput, "password_of_your_pfx_file");
// Perform the process
PdfSecurity.Sign(options);

O exemplo mostra como assinar um documento PDF e definir os parâmetros de entrada e saída separadamente.

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

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

using var pfxStream = File.OpenRead(@"path_to_your_pfx_file.pfx");
var options = new SignOptions(pfxStream, "password_of_your_pfx_file");
// Set input and output file paths
options.Input = new FileData("path_to_your_pdf_file.pdf");
options.Output = 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.

// Create SignOptions object to set instructions
var options = new SignOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf", "path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
// Configure invisible signature
options.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_pdf_file.pdf", "path_to_result_pdf_file.pdf","path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
// 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 arquivo PDF da maneira mais curta possível.

PdfSecurity.Sign(new SignOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf", "path_to_your_pfx_file.pfx", "password_of_your_pfx_file"));

O exemplo demonstra como Assinar um documento PDF com Timestamp.

// Create SignOptions object to set Timestamp
var options = new SignOptions(new TimestampOptions("server_url"));
// Set input and output file paths
options.Input = new FileData("path_to_your_pdf_file.pdf");
options.Output = new FileData("path_to_result_pdf_file.pdf");
// Perform the process
PdfSecurity.Sign(options);

Exceções

ArgumentException

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

Namespace: Documentize Assembly: Documentize.dll

 Português