Class PdfSecurity

Information

Représente le composant Documentize.PdfSecurity. Utilisé pour chiffrer, déchiffrer, signer, et assainir les documents PDF.

public static class PdfSecurity

Héritage

object ← PdfSecurity

Membres hérités

Méthodes

Decrypt(DecryptOptions)

Déchiffre un document PDF.

public static ResultContainer Decrypt(DecryptOptions options)

Paramètres

  • options DecryptOptions : Un objet d’options contenant les instructions pour l’opération.

Retourne

ResultContainer : Un objet contenant le résultat de l’opération.

Exemples

L’exemple montre comment Decrypt un document 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

ArgumentException

Si les options ne sont pas définies.

Encrypt(EncryptOptions)

Chiffre un document PDF.

public static ResultContainer Encrypt(EncryptOptions options)

Paramètres

  • options EncryptOptions : Un objet d’options contenant les instructions pour l’opération.

Retourne

ResultContainer : Un objet contenant le résultat de l’opération.

Exemples

L’exemple montre comment Encrypt un document 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

ArgumentException

Si les options ne sont pas définies.

Sanitize(SanitizeOptions)

Assainit les données cachées d’un document PDF, en éliminant ou transformant les informations sensibles ou inutiles telles que les métadonnées, pièces jointes, annotations, scripts Java, formulaires, calques, index de recherche ou contenu privé.

public static ResultContainer Sanitize(SanitizeOptions options)

Paramètres

  • options SanitizeOptions : Un objet d’options contenant les instructions pour l’opération.

Retourne

ResultContainer : Un objet contenant le résultat de l’opération.

Exemples

L’exemple montre comment Sanitize un document 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);

L’exemple montre comment Sanitize un PDF d’un flux vers un autre flux.

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

L’exemple montre comment Sanitize un PDF d’un fichier vers un flux.

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

L’exemple montre comment Sanitize un PDF d’un fichier vers un flux avec définition manuelle des propriétés d’entrée et de sortie.

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

L’exemple montre comment Sanitize un PDF sans supprimer les métadonné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.RemoveMetadata = false;
// Perform the process
PdfSecurity.Sanitize(options);

L’exemple montre comment Sanitize un PDF sans supprimer les pièces jointes.

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

L’exemple montre comment Sanitize un PDF en convertissant toutes les pages en images et en définissant le DPI du résultat.

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

L’exemple montre comment Sanitize un PDF sans supprimer les scripts Java et les 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);

L’exemple montre comment Sanitize un fichier PDF de la manière la plus concise possible.

PdfSecurity.Sanitize(new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf"));

Exceptions

ArgumentException

Si les options ne sont pas définies.

Sign(SignOptions)

Signe numériquement un document PDF.

public static ResultContainer Sign(SignOptions options)

Paramètres

  • options SignOptions : Un objet d’options contenant les instructions pour l’opération.

Retourne

ResultContainer : Un objet contenant le résultat de l’opération.

Exemples

L’exemple montre comment Sign un document 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);

L’exemple montre comment Sign un document PDF en utilisant des flux.

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

L’exemple montre comment signer un PDF en définissant séparément les paramètres d’entrée et de sortie.

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

L’exemple montre comment Sign un PDF avec un flux de fichier 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);

L’exemple montre comment Sign un PDF avec une signature invisible.

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

L’exemple montre comment Sign un PDF avec des options supplémentaires.

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

L’exemple montre comment Sign un PDF de la manière la plus concise possible.

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

L’exemple montre comment Sign un PDF avec un horodatage.

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

Exceptions

ArgumentException

Si les options ne sont pas définies.

Namespace : Documentize Assembly : Documentize.dll

 Français