Class PdfSecurity
Documentize.PdfSecurity コンポーネントを表します。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)
PDF ドキュメントを復号化します。
public static ResultContainer Decrypt(DecryptOptions options)Parameters
optionsDecryptOptions: 操作の指示を含むオプション オブジェクト。
Returns
ResultContainer : 操作結果を格納したオブジェクト。
Examples
例では 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
オプションが設定されていない場合。
Encrypt(EncryptOptions)
PDF ドキュメントを暗号化します。
public static ResultContainer Encrypt(EncryptOptions options)Parameters
optionsEncryptOptions: 操作の指示を含むオプション オブジェクト。
Returns
ResultContainer : 操作結果を格納したオブジェクト。
Examples
例では 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
オプションが設定されていない場合。
Sanitize(SanitizeOptions)
PDF ドキュメントから隠れたデータを除去し、メタデータ、注釈、JavaScript、プライベートコンテンツなどの機密情報や不要情報を削除または変換します。
public static ResultContainer Sanitize(SanitizeOptions options)Parameters
optionsSanitizeOptions: 操作の指示を含むオプション オブジェクト。
Returns
ResultContainer : 操作結果を格納したオブジェクト。
Examples
例では 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);ストリーム間で PDF をサニタイズする例。
// 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);ファイルからストリームへ PDF をサニタイズする例。
// 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);手動で入力と出力プロパティを設定してサニタイズする例。
// 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);メタデータを削除せずにサニタイズする例。
// 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);添付ファイルを削除せずにサニタイズする例。
// 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);すべてのページを画像に変換し、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);JavaScript とアクションを削除せずにサニタイズする例。
// 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);最短形式で PDF ファイルをサニタイズする例。
// Perform the process
PdfSecurity.Sanitize(new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf"));Exceptions
オプションが設定されていない場合。
Sign(SignOptions)
デジタル署名で PDF ドキュメントに署名します。
public static ResultContainer Sign(SignOptions options)Parameters
optionsSignOptions: 操作の指示を含むオプション オブジェクト。
Returns
ResultContainer : 操作結果を格納したオブジェクト。
Examples
例では 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);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);不可視署名で署名する例。
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);追加オプションを使用して署名する例。
// 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);タイムスタンプ付きで署名する例。
// 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"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfSecurity.Sign(options);Exceptions
オプションが設定されていない場合。
Namespace: Documentize Assembly: Documentize.dll