This is sample code for using Apryse SDK to remove hidden, non-visual content within PDF documents. Using pdftron.PDF.Sanitizer ensures that if metadata, form data, bookmarks, hidden layers, markup annotations, JavaScript, or file attachments are present in a document, that content is permanently destroyed and is not simply disabled or obscured. Sample code is provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, and VB.
To sanitize files with Apryse Server SDK:
Step 1: Follow get started with Server SDK in your preferred language or framework.
Step 2: Add the sample code provided in this guide.
Learn more about Apryse Server SDK.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6using System;
7using System.IO;
8using System.Collections;
9
10using pdftron;
11using pdftron.Common;
12using pdftron.Filters;
13using pdftron.SDF;
14using pdftron.PDF;
15
16using NUnit.Framework;
17
18//------------------------------------------------------------------------------
19// PDFNet's Sanitizer is a security-focused feature that permanently removes
20// hidden, sensitive, or potentially unsafe content from a PDF document.
21// While redaction targets visible page content such as text or graphics,
22// sanitization focuses on non-visual elements and embedded structures.
23//
24// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
25// not merely obscured or disabled. This prevents leakage of sensitive
26// data such as authoring details, editing history, private identifiers,
27// and residual form entries, and neutralizes scripts or attachments.
28//
29// Sanitization is recommended prior to external sharing with clients,
30// partners, or regulatory bodies. It helps align with privacy policies
31// and compliance requirements by permanently removing non-visual data.
32//------------------------------------------------------------------------------
33
34namespace MiscellaneousSamples
35{
36
37 [TestFixture]
38 public class PDFSanitizeTest
39 {
40
41 [Test]
42 public static void Sample()
43 {
44 const string input_path = "TestFiles/";
45
46
47 // The following example illustrates how to retrieve the existing
48 // sanitizable content categories within a document.
49 try
50 {
51 using (PDFDoc doc = new PDFDoc(Utils.GetAssetTempFile(input_path + "numbered.pdf")))
52 {
53 doc.InitSecurityHandler();
54
55 SanitizeOptions opts = Sanitizer.GetSanitizableContent(doc);
56 if (opts.GetMetadata())
57 {
58 Console.WriteLine("Document has metadata.");
59 }
60 if (opts.GetMarkups())
61 {
62 Console.WriteLine("Document has markups.");
63 }
64 if (opts.GetHiddenLayers())
65 {
66 Console.WriteLine("Document has hidden layers.");
67 }
68 Console.WriteLine("Done...");
69 }
70 }
71 catch (PDFNetException e)
72 {
73 Console.WriteLine(e.Message);
74 Assert.True(false);
75 }
76
77
78 // The following example illustrates how to sanitize a document with default options,
79 // which will remove all sanitizable content present within a document.
80 try
81 {
82 using (PDFDoc doc = new PDFDoc(Utils.GetAssetTempFile(input_path + "financial.pdf")))
83 {
84 doc.InitSecurityHandler();
85
86 Sanitizer.SanitizeDocument(doc);
87 doc.Save(Utils.CreateExternalFile("financial_sanitized.pdf"), SDFDoc.SaveOptions.e_linearized);
88 Console.WriteLine("Done...");
89 }
90 }
91 catch (PDFNetException e)
92 {
93 Console.WriteLine(e.Message);
94 Assert.True(false);
95 }
96
97
98 // The following example illustrates how to sanitize a document with custom set options,
99 // which will only remove the content categories specified by the options object.
100 try
101 {
102 using (PDFDoc doc = new PDFDoc(Utils.GetAssetTempFile(input_path + "form1.pdf")))
103 {
104 doc.InitSecurityHandler();
105
106 SanitizeOptions opts = new SanitizeOptions();
107 opts.SetMetadata(true);
108 opts.SetFormData(true);
109 opts.SetBookmarks(true);
110
111 Sanitizer.SanitizeDocument(doc, opts);
112 doc.Save(Utils.CreateExternalFile("form1_sanitized.pdf"), SDFDoc.SaveOptions.e_linearized);
113 Console.WriteLine("Done...");
114 }
115 }
116 catch (PDFNetException e)
117 {
118 Console.WriteLine(e.Message);
119 Assert.True(false);
120 }
121
122 }
123 }
124}
125
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8 "fmt"
9 "testing"
10 "flag"
11 . "github.com/pdftron/pdftron-go/v2"
12)
13
14var licenseKey string
15var modulePath string
16
17func init() {
18 flag.StringVar(&licenseKey, "license", "", "License key for Apryse SDK")
19 flag.StringVar(&modulePath, "modulePath", "", "Module path for Apryse SDK")
20}
21
22//------------------------------------------------------------------------------
23// PDFNet's Sanitizer is a security-focused feature that permanently removes
24// hidden, sensitive, or potentially unsafe content from a PDF document.
25// While redaction targets visible page content such as text or graphics,
26// sanitization focuses on non-visual elements and embedded structures.
27//
28// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
29// not merely obscured or disabled. This prevents leakage of sensitive
30// data such as authoring details, editing history, private identifiers,
31// and residual form entries, and neutralizes scripts or attachments.
32//
33// Sanitization is recommended prior to external sharing with clients,
34// partners, or regulatory bodies. It helps align with privacy policies
35// and compliance requirements by permanently removing non-visual data.
36//------------------------------------------------------------------------------
37
38func TestPDFSanitize(t *testing.T){
39
40 // Relative path to the folder containing the test files.
41 inputPath := "../TestFiles/"
42 outputPath := "../TestFiles/Output/"
43
44 PDFNetInitialize(licenseKey)
45
46 // The following example illustrates how to retrieve the existing
47 // sanitizable content categories within a document.
48 {
49 doc := NewPDFDoc(inputPath + "numbered.pdf")
50 doc.InitSecurityHandler()
51 opts := SanitizerGetSanitizableContent(doc)
52 if opts.GetMetadata() {
53 fmt.Println("Document has metadata.")
54 }
55 if opts.GetMarkups() {
56 fmt.Println("Document has markups.")
57 }
58 if opts.GetHiddenLayers() {
59 fmt.Println("Document has hidden layers.")
60 }
61 fmt.Println("Done...")
62 }
63
64 // The following example illustrates how to sanitize a document with default options,
65 // which will remove all sanitizable content present within a document.
66 {
67 doc := NewPDFDoc(inputPath + "financial.pdf")
68 doc.InitSecurityHandler()
69 SanitizerSanitizeDocument(doc, NewSanitizeOptions())
70 doc.Save(outputPath+"financial_sanitized.pdf", uint(SDFDocE_linearized))
71 fmt.Println("Done...")
72 }
73
74 // The following example illustrates how to sanitize a document with custom set options,
75 // which will only remove the content categories specified by the options object.
76 {
77 options := NewSanitizeOptions()
78 options.SetMetadata(true)
79 options.SetFormData(true)
80 options.SetBookmarks(true)
81
82 doc := NewPDFDoc(inputPath + "form1.pdf")
83 doc.InitSecurityHandler()
84 SanitizerSanitizeDocument(doc, options)
85 doc.Save(outputPath+"form1_sanitized.pdf", uint(SDFDocE_linearized))
86 fmt.Println("Done...")
87 }
88
89 PDFNetTerminate()
90}
91
92
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import java.lang.*;
7import java.awt.*;
8
9import com.pdftron.pdf.*;
10import com.pdftron.sdf.SDFDoc;
11
12//------------------------------------------------------------------------------
13// PDFNet's Sanitizer is a security-focused feature that permanently removes
14// hidden, sensitive, or potentially unsafe content from a PDF document.
15// While redaction targets visible page content such as text or graphics,
16// sanitization focuses on non-visual elements and embedded structures.
17//
18// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
19// not merely obscured or disabled. This prevents leakage of sensitive
20// data such as authoring details, editing history, private identifiers,
21// and residual form entries, and neutralizes scripts or attachments.
22//
23// Sanitization is recommended prior to external sharing with clients,
24// partners, or regulatory bodies. It helps align with privacy policies
25// and compliance requirements by permanently removing non-visual data.
26//------------------------------------------------------------------------------
27public class PDFSanitizeTest {
28
29 public static void main(String[] args) {
30 // Relative paths to folders containing test files.
31 String input_path = "../../TestFiles/";
32 String output_path = "../../TestFiles/Output/";
33
34 PDFNet.initialize(PDFTronLicense.Key());
35
36
37 // The following example illustrates how to retrieve the existing
38 // sanitizable content categories within a document.
39 try (PDFDoc doc = new PDFDoc(input_path + "numbered.pdf")) {
40 doc.initSecurityHandler();
41
42 SanitizeOptions opts = Sanitizer.getSanitizableContent(doc);
43 if (opts.getMetadata())
44 {
45 System.out.println("Document has metadata.");
46 }
47 if (opts.getMarkups())
48 {
49 System.out.println("Document has markups.");
50 }
51 if (opts.getHiddenLayers())
52 {
53 System.out.println("Document has hidden layers.");
54 }
55 System.out.println("Done...");
56 } catch (Exception e) {
57 e.printStackTrace();
58 }
59
60
61 // The following example illustrates how to sanitize a document with default options,
62 // which will remove all sanitizable content present within a document.
63 try (PDFDoc doc = new PDFDoc(input_path + "financial.pdf")) {
64 doc.initSecurityHandler();
65
66 Sanitizer.sanitizeDocument(doc);
67 doc.save(output_path + "financial_sanitized.pdf", SDFDoc.SaveMode.LINEARIZED, null);
68 System.out.println("Done...");
69 } catch (Exception e) {
70 e.printStackTrace();
71 }
72
73
74 // The following example illustrates how to sanitize a document with custom set options,
75 // which will only remove the content categories specified by the options object.
76 try (PDFDoc doc = new PDFDoc(input_path + "form1.pdf")) {
77 doc.initSecurityHandler();
78
79 SanitizeOptions options = new SanitizeOptions();
80 options.setMetadata(true);
81 options.setFormData(true);
82 options.setBookmarks(true);
83
84 Sanitizer.sanitizeDocument(doc, options);
85 doc.save(output_path + "form1_sanitized.pdf", SDFDoc.SaveMode.LINEARIZED, null);
86 System.out.println("Done...");
87 } catch (Exception e) {
88 e.printStackTrace();
89 }
90
91 PDFNet.terminate();
92 }
93}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#include <PDF/PDFNet.h>
7#include <PDF/PDFDoc.h>
8#include <PDF/Sanitizer.h>
9#include <PDF/SanitizeOptions.h>
10#include <iostream>
11
12#include "../../LicenseKey/CPP/LicenseKey.h"
13
14
15using namespace std;
16
17using namespace pdftron;
18using namespace Common;
19using namespace SDF;
20using namespace PDF;
21
22
23//------------------------------------------------------------------------------
24// PDFNet's Sanitizer is a security-focused feature that permanently removes
25// hidden, sensitive, or potentially unsafe content from a PDF document.
26// While redaction targets visible page content such as text or graphics,
27// sanitization focuses on non-visual elements and embedded structures.
28//
29// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
30// not merely obscured or disabled. This prevents leakage of sensitive
31// data such as authoring details, editing history, private identifiers,
32// and residual form entries, and neutralizes scripts or attachments.
33//
34// Sanitization is recommended prior to external sharing with clients,
35// partners, or regulatory bodies. It helps align with privacy policies
36// and compliance requirements by permanently removing non-visual data.
37//------------------------------------------------------------------------------
38
39int main(int argc, char *argv[])
40{
41 int ret = 0;
42 PDFNet::Initialize(LicenseKey);
43
44 // Relative paths to folders containing test files.
45 string input_path = "../../TestFiles/";
46 string output_path = "../../TestFiles/Output/";
47
48 // The following example illustrates how to retrieve the existing
49 // sanitizable content categories within a document.
50 try
51 {
52 PDFDoc doc(input_path + "numbered.pdf");
53 doc.InitSecurityHandler();
54
55 SanitizeOptions opts = Sanitizer::GetSanitizableContent(doc);
56 if (opts.GetMetadata())
57 {
58 cout << "Document has metadata." << endl;
59 }
60 if (opts.GetMarkups())
61 {
62 cout << "Document has markups." << endl;
63 }
64 if (opts.GetHiddenLayers())
65 {
66 cout << "Document has hidden layers." << endl;
67 }
68 cout << "Done..." << endl;
69 }
70 catch(Common::Exception& e)
71 {
72 cout << e << endl;
73 ret = 1;
74 }
75 catch(...)
76 {
77 cout << "Unknown Exception" << endl;
78 ret = 1;
79 }
80
81
82 // The following example illustrates how to sanitize a document with default options,
83 // which will remove all sanitizable content present within a document.
84 try
85 {
86 PDFDoc doc(input_path + "financial.pdf");
87 doc.InitSecurityHandler();
88
89 Sanitizer::SanitizeDocument(doc, 0);
90 doc.Save(output_path + "financial_sanitized.pdf", SDFDoc::e_linearized, 0);
91 cout << "Done..." << endl;
92 }
93 catch(Common::Exception& e)
94 {
95 cout << e << endl;
96 ret = 1;
97 }
98 catch(...)
99 {
100 cout << "Unknown Exception" << endl;
101 ret = 1;
102 }
103
104
105 // The following example illustrates how to sanitize a document with custom set options,
106 // which will only remove the content categories specified by the options object.
107 try
108 {
109 SanitizeOptions options;
110 options.SetMetadata(true);
111 options.SetFormData(true);
112 options.SetBookmarks(true);
113
114 PDFDoc doc(input_path + "form1.pdf");
115 doc.InitSecurityHandler();
116
117 Sanitizer::SanitizeDocument(doc, &options);
118 doc.Save(output_path + "form1_sanitized.pdf", SDFDoc::e_linearized, 0);
119 cout << "Done..." << endl;
120 }
121 catch(Common::Exception& e)
122 {
123 cout << e << endl;
124 ret = 1;
125 }
126 catch(...)
127 {
128 cout << "Unknown Exception" << endl;
129 ret = 1;
130 }
131
132 PDFNet::Terminate();
133 return ret;
134}
135
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6//------------------------------------------------------------------------------
7// PDFNet's Sanitizer is a security-focused feature that permanently removes
8// hidden, sensitive, or potentially unsafe content from a PDF document.
9// While redaction targets visible page content such as text or graphics,
10// sanitization focuses on non-visual elements and embedded structures.
11//
12// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
13// not merely obscured or disabled. This prevents leakage of sensitive
14// data such as authoring details, editing history, private identifiers,
15// and residual form entries, and neutralizes scripts or attachments.
16//
17// Sanitization is recommended prior to external sharing with clients,
18// partners, or regulatory bodies. It helps align with privacy policies
19// and compliance requirements by permanently removing non-visual data.
20//------------------------------------------------------------------------------
21
22const { PDFNet } = require('../../lib/pdfnet.js');
23const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
24
25((exports) => {
26
27 exports.runPDFSanitizeTest = () => {
28
29 const main = async() => {
30 // Relative path to the folder containing test files.
31 const inputPath = '../TestFiles/';
32 const outputPath = '../TestFiles/Output/';
33
34 // The following example illustrates how to retrieve the existing
35 // sanitizable content categories within a document.
36 try {
37 const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'numbered.pdf');
38 if (await doc.initSecurityHandler()) {
39 const opts = await PDFNet.Sanitizer.getSanitizableContent(doc);
40 if (opts.getMetadata()) {
41 console.log('Document has metadata.');
42 }
43 if (opts.getMarkups()) {
44 console.log('Document has markups.');
45 }
46 if (opts.getHiddenLayers()) {
47 console.log('Document has hidden layers.');
48 }
49 }
50 console.log('Done...');
51 } catch (err) {
52 console.log(err.stack);
53 }
54
55 // The following example illustrates how to sanitize a document with default options,
56 // which will remove all sanitizable content present within a document.
57 try {
58 const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'financial.pdf');
59 if (await doc.initSecurityHandler()) {
60 await PDFNet.Sanitizer.sanitizeDocument(doc);
61 await doc.save(outputPath + 'financial_sanitized.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
62 }
63 console.log('Done...');
64 } catch (err) {
65 console.log(err.stack);
66 }
67
68 // The following example illustrates how to sanitize a document with custom set options,
69 // which will only remove the content categories specified by the options object.
70 try {
71 const options = new PDFNet.Sanitizer.SanitizeOptions();
72 options.setMetadata(true);
73 options.setFormData(true);
74 options.setBookmarks(true);
75
76 const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'form1.pdf');
77 if (await doc.initSecurityHandler()) {
78 await PDFNet.Sanitizer.sanitizeDocument(doc, options);
79 await doc.save(outputPath + 'form1_sanitized.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
80 }
81 console.log('Done...');
82 } catch (err) {
83 console.log(err.stack);
84 }
85 };
86 PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
87 };
88 exports.runPDFSanitizeTest();
89})(exports);
90// eslint-disable-next-line spaced-comment
91//# sourceURL=PDFSanitizeTest.js
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3# Consult legal.txt regarding legal and license information.
4#---------------------------------------------------------------------------------------
5
6import site
7site.addsitedir("../../../PDFNetC/Lib")
8import sys
9from PDFNetPython import *
10
11sys.path.append("../../LicenseKey/PYTHON")
12from LicenseKey import *
13
14#------------------------------------------------------------------------------
15# PDFNet's Sanitizer is a security-focused feature that permanently removes
16# hidden, sensitive, or potentially unsafe content from a PDF document.
17# While redaction targets visible page content such as text or graphics,
18# sanitization focuses on non-visual elements and embedded structures.
19#
20# PDFNet Sanitizer ensures hidden or inactive content is destroyed,
21# not merely obscured or disabled. This prevents leakage of sensitive
22# data such as authoring details, editing history, private identifiers,
23# and residual form entries, and neutralizes scripts or attachments.
24#
25# Sanitization is recommended prior to external sharing with clients,
26# partners, or regulatory bodies. It helps align with privacy policies
27# and compliance requirements by permanently removing non-visual data.
28#------------------------------------------------------------------------------
29
30def main():
31 # Relative paths to folders containing test files.
32 input_path = "../../TestFiles/"
33 output_path = "../../TestFiles/Output/"
34
35 PDFNet.Initialize(LicenseKey)
36
37 # The following example illustrates how to retrieve the existing
38 # sanitizable content categories within a document.
39 try:
40 doc = PDFDoc(input_path + "numbered.pdf")
41 doc.InitSecurityHandler()
42
43 opts = Sanitizer.GetSanitizableContent(doc)
44 if opts.GetMetadata():
45 print("Document has metadata.")
46 if opts.GetMarkups():
47 print("Document has markups.")
48 if opts.GetHiddenLayers():
49 print("Document has hidden layers.")
50 print("Done...")
51 except Exception as e:
52 print(e)
53
54 # The following example illustrates how to sanitize a document with default options,
55 # which will remove all sanitizable content present within a document.
56 try:
57 doc = PDFDoc(input_path + "financial.pdf")
58 doc.InitSecurityHandler()
59
60 Sanitizer.SanitizeDocument(doc, None)
61 doc.Save(output_path + "financial_sanitized.pdf", SDFDoc.e_linearized)
62 print("Done...")
63 except Exception as e:
64 print(e)
65
66 # The following example illustrates how to sanitize a document with custom set options,
67 # which will only remove the content categories specified by the options object.
68 try:
69 options = SanitizeOptions()
70 options.SetMetadata(True)
71 options.SetFormData(True)
72 options.SetBookmarks(True)
73
74 doc = PDFDoc(input_path + "form1.pdf")
75 doc.InitSecurityHandler()
76
77 Sanitizer.SanitizeDocument(doc, options)
78 doc.Save(output_path + "form1_sanitized.pdf", SDFDoc.e_linearized)
79 print("Done...")
80 except Exception as e:
81 print(e)
82
83 PDFNet.Terminate()
84
85if __name__ == '__main__':
86 main()
87
88
1<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
4// Consult legal.txt regarding legal and license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10//------------------------------------------------------------------------------
11// PDFNet's Sanitizer is a security-focused feature that permanently removes
12// hidden, sensitive, or potentially unsafe content from a PDF document.
13// While redaction targets visible page content such as text or graphics,
14// sanitization focuses on non-visual elements and embedded structures.
15//
16// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
17// not merely obscured or disabled. This prevents leakage of sensitive
18// data such as authoring details, editing history, private identifiers,
19// and residual form entries, and neutralizes scripts or attachments.
20//
21// Sanitization is recommended prior to external sharing with clients,
22// partners, or regulatory bodies. It helps align with privacy policies
23// and compliance requirements by permanently removing non-visual data.
24//------------------------------------------------------------------------------
25
26 global $LicenseKey;
27 PDFNet::Initialize($LicenseKey);
28 PDFNet::GetSystemFontList(); // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
29
30 // Relative paths to folders containing test files.
31 $input_path = getcwd()."/../../TestFiles/";
32 $output_path = $input_path."Output/";
33
34 // The following example illustrates how to retrieve the existing
35 // sanitizable content categories within a document.
36 try
37 {
38 $doc = new PDFDoc($input_path."numbered.pdf");
39 $doc->InitSecurityHandler();
40
41 $opts = Sanitizer::GetSanitizableContent($doc);
42 if ($opts->GetMetadata())
43 {
44 echo(nl2br("Document has metadata.\n"));
45 }
46 if ($opts->GetMarkups())
47 {
48 echo(nl2br("Document has markups.\n"));
49 }
50 if ($opts->GetHiddenLayers())
51 {
52 echo(nl2br("Document has hidden layers.\n"));
53 }
54 echo(nl2br("Done...\n"));
55 }
56 catch(Exception $e)
57 {
58 echo(nl2br($e->getMessage()."\n"));
59 }
60
61 // The following example illustrates how to sanitize a document with default options,
62 // which will remove all sanitizable content present within a document.
63 try
64 {
65 $doc = new PDFDoc($input_path."financial.pdf");
66 $doc->InitSecurityHandler();
67
68 Sanitizer::SanitizeDocument($doc, null);
69 $doc->Save($output_path."financial_sanitized.pdf", SDFDoc::e_linearized);
70 echo(nl2br("Done...\n"));
71 }
72 catch(Exception $e)
73 {
74 echo(nl2br($e->getMessage()."\n"));
75 }
76
77 // The following example illustrates how to sanitize a document with custom set options,
78 // which will only remove the content categories specified by the options object.
79 try
80 {
81 $options = new SanitizeOptions();
82 $options->SetMetadata(true);
83 $options->SetFormData(true);
84 $options->SetBookmarks(true);
85
86 $doc = new PDFDoc($input_path."form1.pdf");
87 $doc->InitSecurityHandler();
88
89 Sanitizer::SanitizeDocument($doc, $options);
90 $doc->Save($output_path."form1_sanitized.pdf", SDFDoc::e_linearized);
91 echo(nl2br("Done...\n"));
92 }
93 catch(Exception $e)
94 {
95 echo(nl2br($e->getMessage()."\n"));
96 }
97
98 PDFNet::Terminate();
99?>
100
101
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3# Consult legal.txt regarding legal and license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12#------------------------------------------------------------------------------
13# PDFNet's Sanitizer is a security-focused feature that permanently removes
14# hidden, sensitive, or potentially unsafe content from a PDF document.
15# While redaction targets visible page content such as text or graphics,
16# sanitization focuses on non-visual elements and embedded structures.
17#
18# PDFNet Sanitizer ensures hidden or inactive content is destroyed,
19# not merely obscured or disabled. This prevents leakage of sensitive
20# data such as authoring details, editing history, private identifiers,
21# and residual form entries, and neutralizes scripts or attachments.
22#
23# Sanitization is recommended prior to external sharing with clients,
24# partners, or regulatory bodies. It helps align with privacy policies
25# and compliance requirements by permanently removing non-visual data.
26#------------------------------------------------------------------------------
27
28 # Relative paths to folders containing test files.
29 input_path = "../../TestFiles/"
30 output_path = "../../TestFiles/Output/"
31
32 PDFNet.Initialize(PDFTronLicense.Key)
33
34 # The following example illustrates how to retrieve the existing
35 # sanitizable content categories within a document.
36 begin
37 doc = PDFDoc.new(input_path + "numbered.pdf")
38 doc.InitSecurityHandler
39
40 opts = Sanitizer.GetSanitizableContent(doc)
41 if opts.GetMetadata
42 puts "Document has metadata."
43 end
44 if opts.GetMarkups
45 puts "Document has markups."
46 end
47 if opts.GetHiddenLayers
48 puts "Document has hidden layers."
49 end
50 puts "Done..."
51 rescue Exception => e
52 puts e
53 end
54
55 # The following example illustrates how to sanitize a document with default options,
56 # which will remove all sanitizable content present within a document.
57 begin
58 doc = PDFDoc.new(input_path + "financial.pdf")
59 doc.InitSecurityHandler
60
61 Sanitizer.SanitizeDocument(doc, nil)
62 doc.Save(output_path + "financial_sanitized.pdf", SDFDoc::E_linearized)
63 puts "Done..."
64 rescue Exception => e
65 puts e
66 end
67
68 # The following example illustrates how to sanitize a document with custom set options,
69 # which will only remove the content categories specified by the options object.
70 begin
71 options = SanitizeOptions.new
72 options.SetMetadata(true)
73 options.SetFormData(true)
74 options.SetBookmarks(true)
75
76 doc = PDFDoc.new(input_path + "form1.pdf")
77 doc.InitSecurityHandler
78
79 Sanitizer.SanitizeDocument(doc, options)
80 doc.Save(output_path + "form1_sanitized.pdf", SDFDoc::E_linearized)
81 puts "Done..."
82 rescue Exception => e
83 puts e
84 end
85
86 PDFNet.Terminate
87
88
1'
2' Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3'
4
5Imports System
6Imports System.Collections
7
8Imports pdftron
9Imports pdftron.Common
10Imports pdftron.Filters
11Imports pdftron.SDF
12Imports pdftron.PDF
13
14Module PDFSanitizeTestVB
15 Dim pdfNetLoader As PDFNetLoader
16 Sub New()
17 pdfNetLoader = pdftron.PDFNetLoader.Instance()
18 End Sub
19
20 ' PDFNet's Sanitizer is a security-focused feature that permanently removes
21 ' hidden, sensitive, or potentially unsafe content from a PDF document.
22 ' While redaction targets visible page content such as text or graphics,
23 ' sanitization focuses on non-visual elements and embedded structures.
24 '
25 ' PDFNet Sanitizer ensures hidden or inactive content is destroyed,
26 ' not merely obscured or disabled. This prevents leakage of sensitive
27 ' data such as authoring details, editing history, private identifiers,
28 ' and residual form entries, and neutralizes scripts or attachments.
29 '
30 ' Sanitization is recommended prior to external sharing with clients,
31 ' partners, or regulatory bodies. It helps align with privacy policies
32 ' and compliance requirements by permanently removing non-visual data.
33 Sub Main()
34 PDFNet.Initialize(PDFTronLicense.Key)
35
36 Dim input_path As String = "../../../../TestFiles/"
37 Dim output_path As String = "../../../../TestFiles/Output/"
38
39 ' The following example illustrates how to retrieve the existing
40 ' sanitizable content categories within a document.
41 Try
42 Using doc As PDFDoc = New PDFDoc(input_path + "numbered.pdf")
43 doc.InitSecurityHandler()
44 Dim opts As SanitizeOptions = Sanitizer.GetSanitizableContent(doc)
45 If opts.GetMetadata() Then
46 Console.WriteLine("Document has metadata.")
47 End If
48 If opts.GetMarkups() Then
49 Console.WriteLine("Document has markups.")
50 End If
51 If opts.GetHiddenLayers() Then
52 Console.WriteLine("Document has hidden layers.")
53 End If
54 End Using
55 Console.WriteLine("Done...")
56 Catch ex As PDFNetException
57 Console.WriteLine(ex.Message)
58 Catch ex As Exception
59 MsgBox(ex.Message)
60 End Try
61
62 ' The following example illustrates how to sanitize a document with default options,
63 ' which will remove all sanitizable content present within a document.
64 Try
65 Using doc As PDFDoc = New PDFDoc(input_path + "financial.pdf")
66 doc.InitSecurityHandler()
67 Sanitizer.SanitizeDocument(doc)
68 doc.Save(output_path + "financial_sanitized.pdf", SDFDoc.SaveOptions.e_linearized)
69 End Using
70 Console.WriteLine("Done...")
71 Catch ex As PDFNetException
72 Console.WriteLine(ex.Message)
73 Catch ex As Exception
74 MsgBox(ex.Message)
75 End Try
76
77 ' The following example illustrates how to sanitize a document with custom set options,
78 ' which will only remove the content categories specified by the options object.
79 Try
80 Dim options As SanitizeOptions = New SanitizeOptions()
81 options.SetMetadata(True)
82 options.SetFormData(True)
83 options.SetBookmarks(True)
84
85 Using doc As PDFDoc = New PDFDoc(input_path + "form1.pdf")
86 doc.InitSecurityHandler()
87 Sanitizer.SanitizeDocument(doc, options)
88 doc.Save(output_path + "form1_sanitized.pdf", SDFDoc.SaveOptions.e_linearized)
89 End Using
90 Console.WriteLine("Done...")
91 Catch ex As PDFNetException
92 Console.WriteLine(ex.Message)
93 Catch ex As Exception
94 MsgBox(ex.Message)
95 End Try
96
97 PDFNet.Terminate()
98 End Sub
99
100End Module
101
102
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9//------------------------------------------------------------------------------
10// PDFNet's Sanitizer is a security-focused feature that permanently removes
11// hidden, sensitive, or potentially unsafe content from a PDF document.
12// While redaction targets visible page content such as text or graphics,
13// sanitization focuses on non-visual elements and embedded structures.
14//
15// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
16// not merely obscured or disabled. This prevents leakage of sensitive
17// data such as authoring details, editing history, private identifiers,
18// and residual form entries, and neutralizes scripts or attachments.
19//
20// Sanitization is recommended prior to external sharing with clients,
21// partners, or regulatory bodies. It helps align with privacy policies
22// and compliance requirements by permanently removing non-visual data.
23//------------------------------------------------------------------------------
24
25int main(int argc, char *argv[])
26{
27 @autoreleasepool {
28
29 int ret = 0;
30
31 [PTPDFNet Initialize: 0];
32
33
34 // The following example illustrates how to retrieve the existing
35 // sanitizable content categories within a document.
36 @try
37 {
38 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/numbered.pdf"];
39 [doc InitSecurityHandler];
40 PTSanitizeOptions *opts = [PTSanitizer GetSanitizableContent: doc];
41
42 if ([opts GetMetadata]) {
43 NSLog(@"Document has metadata.");
44 }
45 if ([opts GetMarkups]) {
46 NSLog(@"Document has markups.");
47 }
48 if ([opts GetHiddenLayers]) {
49 NSLog(@"Document has hidden layers.");
50 }
51 NSLog(@"Done...");
52 }
53 @catch(NSException *e)
54 {
55 NSLog(@"%@", e.reason);
56 ret = 1;
57 }
58
59
60 // The following example illustrates how to sanitize a document with default options,
61 // which will remove all sanitizable content present within a document.
62 @try
63 {
64 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/financial.pdf"];
65 [doc InitSecurityHandler];
66
67 [PTSanitizer SanitizeDocument: doc options: nil];
68 [doc SaveToFile: @"../../TestFiles/Output/financial_sanitized.pdf" flags: e_ptlinearized ];
69 NSLog(@"Done...");
70 }
71 @catch(NSException *e)
72 {
73 NSLog(@"%@", e.reason);
74 ret = 1;
75 }
76
77
78 // The following example illustrates how to sanitize a document with custom set options,
79 // which will only remove the content categories specified by the options object.
80 @try
81 {
82 PTSanitizeOptions *opts = [[PTSanitizeOptions alloc] init];
83 [opts SetMetadata: YES];
84 [opts SetFormData: YES];
85 [opts SetBookmarks: YES];
86
87 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/form1.pdf"];
88 [doc InitSecurityHandler];
89
90 [PTSanitizer SanitizeDocument: doc options: opts];
91 [doc SaveToFile: @"../../TestFiles/Output/form1_sanitized.pdf" flags: e_ptlinearized ];
92 NSLog(@"Done...");
93 }
94 @catch(NSException *e)
95 {
96 NSLog(@"%@", e.reason);
97 ret = 1;
98 }
99
100 [PTPDFNet Terminate: 0];
101 return ret;
102 }
103}
104
105
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales