تنقية
The Documentize PDF Security for .NET component allows users to sanitize PDF documents. It offers a streamlined process for remove sensitive or unnecessary information such as metadata, attachments, annotations, JavaScripts, forms, layers, search index, or private content. The component provides options to customize information that will be deleted.
Clearing information
- Metadata
- Attachments
- Annotations
- Java Scripts
- Forms
- Layers
- Search index
How to Sanitize PDF documents
To Sanitize a PDF file, follow these steps:
- Instantiate the
SanitizeOptionsclass with the input file path and the output file path. - Run the
Sanitizemethod to apply the sanitization.
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);How to Use Stream for Input and Output data
You can also perform cleaning using PDF documents provided as a stream instead of specifying a file path.
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);How to Sanitize from file to stream
You can set different types of input and output data.
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);How to Sanitize from file to stream by properties
You can set different types of input and output data by using properties.
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);How to Sanitize without removing Metadata
Simply set the RemoveMetadata property to 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);How to Sanitize without removing Attachments
Simply set the RemoveAttachments property to 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);How to Sanitize with converting all pages to images and set result dpi
The example demonstrates how to Sanitize PDF with converting all pages to images and set result dpi.
Set the ConvertPagesToImages property to true. Change ImageDpi if you need,
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);How to Sanitize without removing JavaScripts and Actions
Simply set the RemoveJavaScriptsAndActions property to 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);How to Sanitize PDF file in the shortest possible style
1PdfSecurity.Sanitize(new SanitizeOptions("path_to_your_pdf_file.pdf", "path_to_result_pdf_file.pdf"));Key Features:
- Sanitize PDF Documents: Cleaning a document of potentially dangerous data.
- Customizable options: Choose what to delete and what to leave.
- Convert to images: Convert pages to images, but stay as PDF.