Class PdfSecurity
Representa el componente Documentize.PdfSecurity. Se utiliza para Encriptar, Desencriptar, Firmar, Sanitizar documentos PDF.
public static class PdfSecurityInheritance
Inherited Members
- object.GetType(),
- object.MemberwiseClone(),
- object.ToString(),
- object.Equals(object?),
- object.Equals(object?, object?),
- object.ReferenceEquals(object?, object?),
- object.GetHashCode()
Methods
Decrypt(DecryptOptions)
Desencripta un documento PDF.
public static ResultContainer Decrypt(DecryptOptions options)Parameters
optionsDecryptOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
El ejemplo muestra cómo Desencriptar un 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);Exceptions
Si no se establecen las opciones.
Encrypt(EncryptOptions)
Encripta un documento PDF.
public static ResultContainer Encrypt(EncryptOptions options)Parameters
optionsEncryptOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
El ejemplo muestra cómo Encriptar un 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);Exceptions
Si no se establecen las opciones.
Sanitize(SanitizeOptions)
Sanitiza datos ocultos de un documento PDF, garantizando que la información sensible o innecesaria como metadatos, anotaciones, JavaScripts o contenido privado sea eliminada o transformada.
public static ResultContainer Sanitize(SanitizeOptions options)Parameters
optionsSanitizeOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
El ejemplo muestra cómo Sanitizar un 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);El ejemplo muestra cómo Sanitizar PDF de stream a 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);El ejemplo muestra cómo Sanitizar PDF de archivo a 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);El ejemplo muestra cómo Sanitizar PDF de archivo a stream estableciendo manualmente las propiedades de entrada y salida.
// 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);El ejemplo muestra cómo Sanitizar PDF sin eliminar Metadatos.
// 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);El ejemplo muestra cómo Sanitizar PDF sin eliminar Adjuntos.
// 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);El ejemplo muestra cómo Sanitizar PDF convirtiendo todas las páginas a imágenes y estableciendo DPI del 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);El ejemplo muestra cómo Sanitizar PDF sin eliminar JavaScripts y Acciones.
// 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);El ejemplo muestra cómo Sanitizar un archivo PDF en el estilo más compacto posible.
// Perform the process
PdfSecurity.Sanitize(new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf"));Exceptions
Si no se establecen las opciones.
Sign(SignOptions)
Firma digitalmente un documento PDF.
public static ResultContainer Sign(SignOptions options)Parameters
optionsSignOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
El ejemplo muestra cómo Firmar un 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);El ejemplo muestra cómo Firmar un documento PDF con Stream del archivo 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);El ejemplo muestra cómo Firmar un documento PDF con firma invisible.
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);El ejemplo muestra cómo Firmar un documento PDF con opciones adicionales.
// 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);El ejemplo muestra cómo Firmar un documento PDF con marca de tiempo.
// 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
Si no se establecen las opciones.
Namespace: Documentize Assembly: Documentize.dll