サニタイズ
Documentize PDF Security for .NET コンポーネントは、PDF ドキュメントをサニタイズする機能を提供します。メタデータ、添付ファイル、注釈、JavaScripts、フォーム、レイヤー、検索インデックス、またはプライベートコンテンツなどの機密または不要な情報を削除するためのシンプルなプロセスを実現します。コンポーネントは、削除する情報をカスタマイズできるオプションを提供します。
情報のクリア
- メタデータ
- 添付ファイル
- 注釈
- Java Scripts
- フォーム
- レイヤー
- 検索インデックス
PDF ドキュメントのサニタイズ方法
PDF ファイルをサニタイズするには、以下の手順を実行します。
- 入力ファイルパスと出力ファイルパスを指定して
SanitizeOptionsクラスのインスタンスを作成します。 Sanitizeメソッドを実行してサニタイズを適用します。
1// Create SanitizeOptions object to set input and output files
2var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
3// Perform the process
4PdfSecurity.Sanitize(options);入出力データにストリームを使用する方法
ファイルパスを指定せず、ストリームとして提供された PDF ドキュメントでクリーニングを実行することもできます。
1// Prepare input and output streams
2using var inputStream = File.OpenRead("path_to_your_pdf_file.pdf");
3using var outputStream = new MemoryStream();
4// Create SanitizeOptions object to set input and output streams
5var options = new SanitizeOptions(inputStream, outputStream);
6// Perform the process
7PdfSecurity.Sanitize(options);ファイルからストリームへのサニタイズ方法
入力と出力のデータタイプを組み合わせて設定できます。
1// Prepare output stream
2using var outputStream = new MemoryStream();
3// Create SanitizeOptions object to set input file and output stream
4var options = new SanitizeOptions("path_to_your_pdf_file.pdf", outputStream);
5// Perform the process
6PdfSecurity.Sanitize(options);プロパティを使用したファイルからストリームへのサニタイズ方法
プロパティを使って入力と出力のデータタイプを設定できます。
1// Prepare output stream
2using var outputStream = new MemoryStream();
3// Create SanitizeOptions object
4var options = new SanitizeOptions();
5//Set Input file
6options.Input = new FileData("path_to_your_pdf_file.pdf");
7//Set Output stream
8options.Output = new StreamData(outputStream);
9// Perform the process
10PdfSecurity.Sanitize(options);メタデータを削除せずにサニタイズする方法
RemoveMetadata プロパティを false に設定します。
1// Create SanitizeOptions object to set input and output files
2var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
3options.RemoveMetadata = false;
4// Perform the process
5PdfSecurity.Sanitize(options);添付ファイルを削除せずにサニタイズする方法
RemoveAttachments プロパティを false に設定します。
1// Create SanitizeOptions object to set input and output files
2var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
3options.RemoveAttachments = false;
4// Perform the process
5PdfSecurity.Sanitize(options);すべてのページを画像に変換し、結果の DPI を設定してサニタイズする方法
すべてのページを画像に変換し、結果の DPI を設定する例です。ConvertPagesToImages プロパティを true にし、必要に応じて ImageDpi を変更します。
1// Create SanitizeOptions object to set input and output files
2var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
3// Turn on conversion and set dpi
4options.ConvertPagesToImages = true;
5options.ImageDpi = 200;
6// Perform the process
7PdfSecurity.Sanitize(options);JavaScripts と Actions を削除せずにサニタイズする方法
RemoveJavaScriptsAndActions プロパティを false に設定します。
1// Create SanitizeOptions object to set input and output files
2var options = new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf");
3options.RemoveJavaScriptsAndActions = false;
4// Perform the process
5PdfSecurity.Sanitize(options);最も簡潔な形式で PDF ファイルをサニタイズする方法
1PdfSecurity.Sanitize(new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf"));主な機能
- PDF ドキュメントのサニタイズ: 危険なデータを除去して文書をクリーンにします。
- カスタマイズ可能なオプション: 削除する項目と残す項目を選択できます。
- 画像への変換: ページを画像に変換しながら PDF として保持します。