> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/sanitization/sanitize.md).

# Sanitize a PDF document on Apryse Server SDK

Learn how to sanitize content from a PDF document using Apryse SDK API. Remove sensitive data securely.

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.

{% hint style="warning" %}
**Warn**

Document sanitization is irreversible, so create backups of any documents before use.
{% endhint %}

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

* [Content detection](#content-detection)
* [Document sanitization](#document-sanitization)

## 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:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
SanitizeOptions options = new SanitizeOptions();
options.SetMetadata(true);
options.SetFormData(true);
options.SetBookmarks(true);

PDFDoc doc = new PDFDoc(filename);
Sanitizer.SanitizeDocument(doc, options);
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
options := NewSanitizeOptions()
options.SetMetadata(true)
options.SetFormData(true)
options.SetBookmarks(true)

doc := NewPDFDoc(filename)
SanitizerSanitizeDocument(doc, options)
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
SanitizeOptions options;
options.SetMetadata(true);
options.SetFormData(true);
options.SetBookmarks(true);

PDFDoc doc(filename);
Sanitizer::SanitizeDocument(doc, &options);
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
SanitizeOptions options = new SanitizeOptions();
options.setMetadata(true);
options.setFormData(true);
options.setBookmarks(true);

PDFDoc doc = new PDFDoc(filename);
Sanitizer.sanitizeDocument(doc, options);

```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
const options = new PDFNet.Sanitizer.SanitizeOptions();
options.setMetadata(true);
options.setFormData(true);
options.setBookmarks(true);

const doc = await PDFNet.PDFDoc.createFromURL(filename);
await PDFNet.Sanitizer.sanitizeDocument(doc, options);
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
$options = new SanitizeOptions();
$options->SetMetadata(true);
$options->SetFormData(true);
$options->SetBookmarks(true);

$doc = new PDFDoc(filename);
Sanitizer::SanitizeDocument($doc, $options);
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
options = SanitizeOptions.new
options.SetMetadata(true)
options.SetFormData(true)
options.SetBookmarks(true)

doc = PDFDoc.new(filename)
Sanitizer.SanitizeDocument(doc, options)
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
PTSanitizeOptions *opts = [[PTSanitizeOptions alloc] init];
[opts SetMetadata: YES];
[opts SetFormData: YES];
[opts SetBookmarks: YES];

PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
[PTSanitizer SanitizeDocument: doc options: opts];
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
options = SanitizeOptions()
options.SetMetadata(True)
options.SetFormData(True)
options.SetBookmarks(True)

doc = PDFDoc(filename)
Sanitizer.SanitizeDocument(doc, options)
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
Dim options As SanitizeOptions = New SanitizeOptions()
options.SetMetadata(True)
options.SetFormData(True)
options.SetBookmarks(True)

Dim doc As PDFDoc = New PDFDoc(filename)
Sanitizer.SanitizeDocument(doc, options)
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**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.
{% endhint %}

See our [full code sample for PDF sanitization](/core/get-started/samples/pdfsanitizetest.md) 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/sanitization/sanitize.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
