Очистка
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
Как очистить 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 результата
В примере показано, как очистить PDF с конвертацией всех страниц в изображения и задать 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);Как выполнить очистку без удаления JavaScript и действий
Просто установите свойство 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"));Ключевые возможности:
- 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.