For the complete documentation index, see llms.txt. This page is also available as Markdown.

Sanitize a PDF document on Apryse Server SDK

Apryse SDK's Sanitizer ensures that if specified content categories are present in a document, the content is permanently destroyed, not simply disabled or obscured. This prevents leakage of sensitive data such as authoring details, editing history, private identifiers, residual form entries, and neutralizes scripts or attachments.

Sanitization is recommended prior to external sharing with clients, partners, or regulatory bodies. It helps align with privacy policies and compliance requirements by permanently removing any potentially sensitive hidden data.

The sanitization process in the Apryse SDK consists of two parts:

Content detection

A user calls pdftron.PDF.Sanitizer.GetSanitizableContent() to retrieve a SanitizeOptions object outlining the sanitizable content groups present within the document. For each content group in the provided document, the corresponding category is automatically enabled. This helps you understand how sanitization will modify the document and make informed decisions about which content groups to remove.

Document sanitization

With pdftron.PDF.Sanitizer.SanitizeDocument(), you can instruct the sanitizer to permanently strip the specified content from the document.

You can optionally provide a SanitizeOptions object to specify which content categories to remove. For example, remove only metadata, form data, and bookmarks while leaving other content intact. Only the categories explicitly enabled in the SanitizeOptions object are sanitized. All other content remains unchanged.

In summary, the behavior differs depending on how sanitizeDocument() is called:

  • SanitizeDocument(doc) → Removes all sanitizable content.

  • SanitizeDocument(doc, options) → Removes only the content categories explicitly enabled in the SanitizeOptions object.

  • SanitizeDocument(doc, new SanitizeOptions()) → Removes no content because an empty SanitizeOptions object is provided with no categories enabled.

For example, to sanitize content from a PDF document using an optional SanitizeOptions() object with categories, use the following code:

Info

When using a SanitizeOptions object, sanitation is opt-in. All content categories are disabled by default and must be explicitly enabled. For example, SetFormData(true) removes form data, whereas SetFormData() leaves the option disabled and does not remove form data from the document.

See our full code sample for PDF sanitization to learn how to use pdftron.PDF.Sanitizer to permanently remove hidden and sensitive content from PDF documents. The sample is available in C#, Go, Java, C++, JavaScript, Python, PHP, Ruby, VB, and Objective-C.

Last updated

Was this helpful?