Sample code for using Apryse SDK to remove potentially sensitive content within PDF documents. Using 'pdftron.PDF.Redactor' makes sure that if a portion of an image, text, or vector graphics is contained in a redaction region, that portion is destroyed and is not simply hidden with clipping or image masks. Sample code provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby and VB.
To redact 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
To use this feature in production, your license key will need the Redaction Package. Trial keys already include all packages.
Learn more about our Server SDK.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 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
16namespace PDFNetSamples
17{
18	// PDF Redactor is a separately licensable Add-on that offers options to remove 
19	// (not just covering or obscuring) content within a region of PDF. 
20	// With printed pages, redaction involves blacking-out or cutting-out areas of 
21	// the printed page. With electronic documents that use formats such as PDF, 
22	// redaction typically involves removing sensitive content within documents for 
23	// safe distribution to courts, patent and government institutions, the media, 
24	// customers, vendors or any other audience with restricted access to the content. 
25	//
26	// The redaction process in PDFNet consists of two steps:
27	// 
28	//  a) Content identification: A user applies redact annotations that specify the 
29	// pieces or regions of content that should be removed. The content for redaction 
30	// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
31	// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
32	// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
33	// can see, move and redefine these annotations.
34	//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
35	// PDFNet to apply the redact regions, after which the content in the area specified 
36	// by the redact annotations is removed. The redaction function includes number of 
37	// options to control the style of the redaction overlay (including color, text, 
38	// font, border, transparency, etc.).
39	// 
40	// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
41	// is contained in a redaction region, that portion of the image or path data is 
42	// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
43	// be used to review and remove metadata and other content that can exist in a PDF 
44	// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
45	// Platform (XMP) content.
46	class Class1
47	{
48		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
49		static Class1() {}
50		
51		static void Redact(string input, string output, ArrayList rarr, Redactor.Appearance app)
52		{
53			using (PDFDoc doc = new PDFDoc(input))
54			{
55				doc.InitSecurityHandler();
56				Redactor.Redact(doc, rarr, app, false, true);
57				doc.Save(output, SDFDoc.SaveOptions.e_linearized);
58			}
59		}
60
61		/// <summary>
62		/// The following sample illustrates how to redact a PDF document using 'pdftron.PDF.Redactor'.
63		/// </summary>
64		static void Main(string[] args)
65		{
66			PDFNet.Initialize(PDFTronLicense.Key);
67
68			string input_path = "../../../../TestFiles/";
69			string output_path = "../../../../TestFiles/Output/";
70			try
71			{
72				ArrayList rarr = new ArrayList();
73				rarr.Add(new Redactor.Redaction(1, new Rect(100, 100, 550, 600), false, "Top Secret"));
74				rarr.Add(new Redactor.Redaction(2, new Rect(30, 30, 450, 450), true, "Negative Redaction"));
75				rarr.Add(new Redactor.Redaction(2, new Rect(0, 0, 100, 100), false, "Positive"));
76				rarr.Add(new Redactor.Redaction(2, new Rect(100, 100, 200, 200), false, "Positive"));
77				rarr.Add(new Redactor.Redaction(2, new Rect(300, 300, 400, 400), false, ""));
78				rarr.Add(new Redactor.Redaction(2, new Rect(500, 500, 600, 600), false, ""));
79				rarr.Add(new Redactor.Redaction(3, new Rect(0, 0, 700, 20), false, ""));
80
81				Redactor.Appearance app = new Redactor.Appearance();
82				app.RedactionOverlay = true;
83				app.Border = false;
84				app.ShowRedactedContentRegions = true;
85
86				Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", rarr, app);
87
88				Console.WriteLine("Done...");
89			}
90			catch (PDFNetException e)
91			{
92				Console.WriteLine(e.Message);
93			}
94			PDFNet.Terminate();
95		}
96	}
97}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8	"fmt"
9	. "pdftron"
10)
11
12import  "pdftron/Samples/LicenseKey/GO"
13
14// PDF Redactor is a separately licensable Add-on that offers options to remove 
15// (not just covering or obscuring) content within a region of PDF. 
16// With printed pages, redaction involves blacking-out or cutting-out areas of 
17// the printed page. With electronic documents that use formats such as PDF, 
18// redaction typically involves removing sensitive content within documents for 
19// safe distribution to courts, patent and government institutions, the media, 
20// customers, vendors or any other audience with restricted access to the content. 
21//
22// The redaction process in PDFNet consists of two steps:
23// 
24//  a) Content identification: A user applies redact annotations that specify the 
25// pieces or regions of content that should be removed. The content for redaction 
26// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
27// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
28// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
29// can see, move and redefine these annotations.
30//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
31// PDFNet to apply the redact regions, after which the content in the area specified 
32// by the redact annotations is removed. The redaction function includes number of 
33// options to control the style of the redaction overlay (including color, text, 
34// font, border, transparency, etc.).
35// 
36// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
37// is contained in a redaction region, that portion of the image or path data is 
38// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
39// be used to review and remove metadata and other content that can exist in a PDF 
40// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
41// Platform (XMP) content.
42
43func Redact(input string, output string, vec VectorRedaction, app Appearance){
44    doc := NewPDFDoc(input)
45    if doc.InitSecurityHandler(){
46        RedactorRedact(doc, vec, app, false, true)
47        doc.Save(output, uint(SDFDocE_linearized))
48	}
49}                                  
50
51func main(){
52
53    // Relative path to the folder containing the test files.
54    inputPath := "../../TestFiles/"
55    outputPath := "../../TestFiles/Output/"
56    
57    PDFNetInitialize(PDFTronLicense.Key)
58    
59    vec := NewVectorRedaction()
60    vec.Add(NewRedaction(1, NewRect(100.0, 100.0, 550.0, 600.0), false, "Top Secret"))
61    vec.Add(NewRedaction(2, NewRect(30.0, 30.0, 450.0, 450.0), true, "Negative Redaction"))
62    vec.Add(NewRedaction(2, NewRect(0.0, 0.0, 100.0, 100.0), false, "Positive"))
63    vec.Add(NewRedaction(2, NewRect(100.0, 100.0, 200.0, 200.0), false, "Positive"))
64    vec.Add(NewRedaction(2, NewRect(300.0, 300.0, 400.0, 400.0), false, ""))
65    vec.Add(NewRedaction(2, NewRect(500.0, 500.0, 600.0, 600.0), false, ""))
66    vec.Add(NewRedaction(3, NewRect(0.0, 0.0, 700.0, 20.0), false, ""))
67	
68    app := NewAppearance() 
69    app.SetRedactionOverlay(true)
70    app.SetBorder(false)
71    app.SetShowRedactedContentRegions(true)
72    Redact(inputPath + "newsletter.pdf", outputPath + "redacted.pdf", vec, app)
73    
74    PDFNetTerminate()
75    fmt.Println("Done...")
76}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 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// PDF Redactor is a separately licensable Add-on that offers options to remove 
14// (not just covering or obscuring) content within a region of PDF. 
15// With printed pages, redaction involves blacking-out or cutting-out areas of 
16// the printed page. With electronic documents that use formats such as PDF, 
17// redaction typically involves removing sensitive content within documents for 
18// safe distribution to courts, patent and government institutions, the media, 
19// customers, vendors or any other audience with restricted access to the content. 
20//
21// The redaction process in PDFNet consists of two steps:
22// 
23//  a) Content identification: A user applies redact annotations that specify the 
24// pieces or regions of content that should be removed. The content for redaction 
25// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
26// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
27// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
28// can see, move and redefine these annotations.
29//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
30// PDFNet to apply the redact regions, after which the content in the area specified 
31// by the redact annotations is removed. The redaction function includes number of 
32// options to control the style of the redaction overlay (including color, text, 
33// font, border, transparency, etc.).
34// 
35// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
36// is contained in a redaction region, that portion of the image or path data is 
37// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
38// be used to review and remove metadata and other content that can exist in a PDF 
39// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
40// Platform (XMP) content.
41public class PDFRedactTest {
42
43    public static void redact(String input, String output, Redactor.Redaction[] vec, Redactor.Appearance app) {
44        try (PDFDoc doc = new PDFDoc(input)) {
45            if (doc.initSecurityHandler()) {
46                Redactor.redact(doc, vec, app, false, true);
47                doc.save(output, SDFDoc.SaveMode.REMOVE_UNUSED, null);
48            }
49        } catch (Exception e) {
50            e.printStackTrace();
51        }
52    }
53
54    public static void main(String[] args) {
55        // Relative paths to folders containing test files.
56        String input_path = "../../TestFiles/";
57        String output_path = "../../TestFiles/Output/";
58
59        PDFNet.initialize(PDFTronLicense.Key());
60
61        try {
62            Redactor.Redaction[] vec = new Redactor.Redaction[7];
63            vec[0] = new Redactor.Redaction(1, new Rect(100, 100, 550, 600), false, "Top Secret");
64            vec[1] = new Redactor.Redaction(2, new Rect(30, 30, 450, 450), true, "Negative Redaction");
65            vec[2] = new Redactor.Redaction(2, new Rect(0, 0, 100, 100), false, "Positive");
66            vec[3] = new Redactor.Redaction(2, new Rect(100, 100, 200, 200), false, "Positive");
67            vec[4] = new Redactor.Redaction(2, new Rect(300, 300, 400, 400), false, "");
68            vec[5] = new Redactor.Redaction(2, new Rect(500, 500, 600, 600), false, "");
69            vec[6] = new Redactor.Redaction(3, new Rect(0, 0, 700, 20), false, "");
70            
71            Redactor.Appearance app = new Redactor.Appearance();
72            app.redactionOverlay = true;
73            app.border = false;
74            app.showRedactedContentRegions = true;
75
76            redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app);
77
78            System.out.println("Done...");
79        } catch (Exception e) {
80            e.printStackTrace();
81        }
82        PDFNet.terminate();
83    }
84}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 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/Redactor.h>
9
10#include <iostream>
11#include <vector>
12#include "../../LicenseKey/CPP/LicenseKey.h"
13
14using namespace std;
15
16using namespace pdftron;
17using namespace Common;
18using namespace SDF;
19using namespace PDF;
20
21// PDF Redactor is a separately licensable Add-on that offers options to remove 
22// (not just covering or obscuring) content within a region of PDF. 
23// With printed pages, redaction involves blacking-out or cutting-out areas of 
24// the printed page. With electronic documents that use formats such as PDF, 
25// redaction typically involves removing sensitive content within documents for 
26// safe distribution to courts, patent and government institutions, the media, 
27// customers, vendors or any other audience with restricted access to the content. 
28//
29// The redaction process in PDFNet consists of two steps:
30// 
31//  a) Content identification: A user applies redact annotations that specify the 
32// pieces or regions of content that should be removed. The content for redaction 
33// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
34// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
35// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
36// can see, move and redefine these annotations.
37//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
38// PDFNet to apply the redact regions, after which the content in the area specified 
39// by the redact annotations is removed. The redaction function includes number of 
40// options to control the style of the redaction overlay (including color, text, 
41// font, border, transparency, etc.).
42// 
43// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
44// is contained in a redaction region, that portion of the image or path data is 
45// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
46// be used to review and remove metadata and other content that can exist in a PDF 
47// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
48// Platform (XMP) content.
49
50static void Redact(const string& input, const string& output, const vector<Redactor::Redaction>& vec, Redactor::Appearance app) 
51{
52	PDFDoc doc(input);
53	if (doc.InitSecurityHandler()) {
54		Redactor::Redact(doc, vec, app, false, true);
55		doc.Save(output, SDFDoc::e_linearized, 0);
56	}
57}
58
59int main(int argc, char *argv[])
60{
61	int ret = 0;
62
63	// Relative paths to folders containing test files.
64	string input_path =  "../../TestFiles/";
65	string output_path = "../../TestFiles/Output/";
66
67	PDFNet::Initialize(LicenseKey);
68
69	try  
70	{	 
71		vector<Redactor::Redaction> vec;
72		vec.push_back(Redactor::Redaction(1, Rect(100, 100, 550, 600), false, "Top Secret"));
73		vec.push_back(Redactor::Redaction(2, Rect(30, 30, 450, 450), true, "Negative Redaction"));
74		vec.push_back(Redactor::Redaction(2, Rect(0, 0, 100, 100), false, "Positive"));
75		vec.push_back(Redactor::Redaction(2, Rect(100, 100, 200, 200), false, "Positive"));
76		vec.push_back(Redactor::Redaction(2, Rect(300, 300, 400, 400), false, ""));
77		vec.push_back(Redactor::Redaction(2, Rect(500, 500, 600, 600), false, ""));
78		vec.push_back(Redactor::Redaction(3, Rect(0, 0, 700, 20), false, ""));
79
80		Redactor::Appearance app;
81		app.RedactionOverlay = true;
82		app.Border = false;
83		app.ShowRedactedContentRegions = true;
84
85		Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app);
86
87		cout << "Done..." << endl;
88	}
89	catch(Common::Exception& e)
90	{
91		cout << e << endl;
92		ret = 1;
93	}
94	catch(...)
95	{
96		cout << "Unknown Exception" << endl;
97		ret = 1;
98	}
99
100	PDFNet::Terminate();
101	return ret;
102}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6// PDF Redactor is a separately licensable Add-on that offers options to remove 
7// (not just covering or obscuring) content within a region of PDF. 
8// With printed pages, redaction involves blacking-out or cutting-out areas of 
9// the printed page. With electronic documents that use formats such as PDF, 
10// redaction typically involves removing sensitive content within documents for 
11// safe distribution to courts, patent and government institutions, the media, 
12// customers, vendors or any other audience with restricted access to the content. 
13//
14// The redaction process in PDFNet consists of two steps:
15// 
16//  a) Content identification: A user applies redact annotations that specify the 
17// pieces or regions of content that should be removed. The content for redaction 
18// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
19// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
20// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
21// can see, move and redefine these annotations.
22//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
23// PDFNet to apply the redact regions, after which the content in the area specified 
24// by the redact annotations is removed. The redaction function includes number of 
25// options to control the style of the redaction overlay (including color, text, 
26// font, border, transparency, etc.).
27// 
28// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
29// is contained in a redaction region, that portion of the image or path data is 
30// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
31// be used to review and remove metadata and other content that can exist in a PDF 
32// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
33// Platform (XMP) content.
34
35const { PDFNet } = require('@pdftron/pdfnet-node');
36const PDFTronLicense = require('../LicenseKey/LicenseKey');
37
38((exports) => {
39
40  exports.runPDFRedactTest = () => {
41    const redact = async(input, output, vec, app) => {
42      const doc = await PDFNet.PDFDoc.createFromFilePath(input);
43      if (await doc.initSecurityHandler()) {
44        PDFNet.Redactor.redact(doc, vec, app, false, true);
45        await doc.save(output, PDFNet.SDFDoc.SaveOptions.e_linearized);
46      }
47    };
48
49    const main = async() => {
50      // Relative path to the folder containing test files.
51      const inputPath = '../TestFiles/';
52      try {
53        const redactionArray = []; // we will contain a list of redaction objects in this array
54        redactionArray.push(await PDFNet.Redactor.redactionCreate(1, (await PDFNet.Rect.init(100, 100, 550, 600)), false, 'Top Secret'));
55        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(30, 30, 450, 450)), true, 'Negative Redaction'));
56        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(0, 0, 100, 100)), false, 'Positive'));
57        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(100, 100, 200, 200)), false, 'Positive'));
58        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(300, 300, 400, 400)), false, ''));
59        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(500, 500, 600, 600)), false, ''));
60        redactionArray.push(await PDFNet.Redactor.redactionCreate(3, (await PDFNet.Rect.init(0, 0, 700, 20)), false, ''));
61
62        const appear = { redaction_overlay: true, border: false, show_redacted_content_regions: true };
63        await redact(inputPath + 'newsletter.pdf', inputPath + 'Output/redacted.pdf', redactionArray, appear);
64
65        console.log('Done...');
66      } catch (err) {
67        console.log(err.stack);
68      }
69    };
70    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
71  };
72  exports.runPDFRedactTest();
73})(exports);
74// eslint-disable-next-line spaced-comment
75//# sourceURL=PDFRedactTest.js
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding 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# PDF Redactor is a separately licensable Add-on that offers options to remove 
16# (not just covering or obscuring) content within a region of PDF. 
17# With printed pages, redaction involves blacking-out or cutting-out areas of 
18# the printed page. With electronic documents that use formats such as PDF, 
19# redaction typically involves removing sensitive content within documents for 
20# safe distribution to courts, patent and government institutions, the media, 
21# customers, vendors or any other audience with restricted access to the content. 
22#
23# The redaction process in PDFNet consists of two steps:
24# 
25#  a) Content identification: A user applies redact annotations that specify the 
26# pieces or regions of content that should be removed. The content for redaction 
27# can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
28# as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
29# or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
30# can see, move and redefine these annotations.
31#  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
32# PDFNet to apply the redact regions, after which the content in the area specified 
33# by the redact annotations is removed. The redaction function includes number of 
34# options to control the style of the redaction overlay (including color, text, 
35# font, border, transparency, etc.).
36# 
37# PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
38# is contained in a redaction region, that portion of the image or path data is 
39# destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
40# be used to review and remove metadata and other content that can exist in a PDF 
41# document, including XML Forms Architecture (XFA) content and Extensible Metadata 
42# Platform (XMP) content.
43
44def Redact(input, output, vec, app):
45    doc = PDFDoc(input)
46    if doc.InitSecurityHandler():
47        Redactor.Redact(doc, vec, app, False, True)
48        doc.Save(output, SDFDoc.e_linearized)
49                                  
50
51def main():
52    # Relative path to the folder containing the test files.
53    input_path = "../../TestFiles/"
54    output_path = "../../TestFiles/Output/"
55    
56    PDFNet.Initialize(LicenseKey)
57    
58    vec = VectorRedaction()
59    vec.append(Redaction(1, Rect(100, 100, 550, 600), False, "Top Secret"))
60    vec.append(Redaction(2, Rect(30, 30, 450, 450), True, "Negative Redaction"))
61    vec.append(Redaction(2, Rect(0, 0, 100, 100), False, "Positive"))
62    vec.append(Redaction(2, Rect(100, 100, 200, 200), False, "Positive"))
63    vec.append(Redaction(2, Rect(300, 300, 400, 400), False, ""))
64    vec.append(Redaction(2, Rect(500, 500, 600, 600), False, ""))
65    vec.append(Redaction(3, Rect(0, 0, 700, 20), False, ""))
66	
67    app = Appearance() 
68    app.RedactionOverlay = True
69    app.Border = False
70    app.ShowRedactedContentRegions = True
71    Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app)
72    
73    PDFNet.Terminate()
74    print("Done...")
75
76if __name__ == '__main__':
77    main()
1<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
4// Consult LICENSE.txt regarding license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10// PDF Redactor is a separately licensable Add-on that offers options to remove 
11// (not just covering or obscuring) content within a region of PDF. 
12// With printed pages, redaction involves blacking-out or cutting-out areas of 
13// the printed page. With electronic documents that use formats such as PDF, 
14// redaction typically involves removing sensitive content within documents for 
15// safe distribution to courts, patent and government institutions, the media, 
16// customers, vendors or any other audience with restricted access to the content. 
17//
18// The redaction process in PDFNet consists of two steps:
19// 
20//  a) Content identification: A user applies redact annotations that specify the 
21// pieces or regions of content that should be removed. The content for redaction 
22// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
23// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
24// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
25// can see, move and redefine these annotations.
26//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
27// PDFNet to apply the redact regions, after which the content in the area specified 
28// by the redact annotations is removed. The redaction function includes number of 
29// options to control the style of the redaction overlay (including color, text, 
30// font, border, transparency, etc.).
31// 
32// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
33// is contained in a redaction region, that portion of the image or path data is 
34// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
35// be used to review and remove metadata and other content that can exist in a PDF 
36// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
37// Platform (XMP) content.
38	
39function Redact($input, $output, $vec, $app) {
40	$doc = new PDFDoc($input);
41	if ($doc->InitSecurityHandler()) {
42		Redactor::Redact($doc, $vec, $app, false, true);
43		$doc->Save($output, SDFDoc::e_linearized);
44	}
45
46}
47
48	# Relative path to the folder containing the test files.
49	$input_path = getcwd()."/../../TestFiles/";
50	$output_path = $input_path."Output/";
51
52	PDFNet::Initialize($LicenseKey);
53	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.
54
55	$vec = new VectorRedaction();
56	$vec->push(new Redaction(1, new Rect(100.0, 100.0, 550.0, 600.0), false, "Top Secret"));
57	$vec->push(new Redaction(2, new Rect(30.0, 30.0, 450.0, 450.0), true, "Negative Redaction"));
58	$vec->push(new Redaction(2, new Rect(0.0, 0.0, 100.0, 100.0), false, "Positive"));
59	$vec->push(new Redaction(2, new Rect(100.0, 100.0, 200.0, 200.0), false, "Positive"));
60   	$vec->push(new Redaction(2, new Rect(300.0, 300.0, 400.0, 400.0), false, ""));
61	$vec->push(new Redaction(2, new Rect(500.0, 500.0, 600.0, 600.0), false, ""));
62	$vec->push(new Redaction(3, new Rect(0.0, 0.0, 700.0, 20.0), false, ""));
63	
64	$app = new Appearance(); 
65	$app->RedactionOverlay = true;
66	$app->Border = false;
67	$app->ShowRedactedContentRegions = true;
68	Redact($input_path."newsletter.pdf", $output_path."redacted.pdf", $vec, $app);
69    PDFNet::Terminate();
70	echo "Done...\n";	
71?>
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12
13# PDF Redactor is a separately licensable Add-on that offers options to remove 
14# (not just covering or obscuring) content within a region of PDF. 
15# With printed pages, redaction involves blacking-out or cutting-out areas of 
16# the printed page. With electronic documents that use formats such as PDF, 
17# redaction typically involves removing sensitive content within documents for 
18# safe distribution to courts, patent and government institutions, the media, 
19# customers, vendors or any other audience with restricted access to the content. 
20#
21# The redaction process in PDFNet consists of two steps:
22# 
23#  a) Content identification: A user applies redact annotations that specify the 
24# pieces or regions of content that should be removed. The content for redaction 
25# can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
26# as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
27# or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
28# can see, move and redefine these annotations.
29#  b) Content removal: Using 'pdftron.PDF.Redactor.Redact' the user instructs 
30# PDFNet to apply the redact regions, after which the content in the area specified 
31# by the redact annotations is removed. The redaction function includes number of 
32# options to control the style of the redaction overlay (including color, text, 
33# font, border, transparency, etc.).
34# 
35# PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
36# is contained in a redaction region, that portion of the image or path data is 
37# destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
38# be used to review and remove metadata and other content that can exist in a PDF 
39# document, including XML Forms Architecture (XFA) content and Extensible Metadata 
40# Platform (XMP) content.
41
42def Redact(input, output, vec, app)
43	doc = PDFDoc.new(input)
44	if doc.InitSecurityHandler
45		Redactor.Redact(doc, vec, app, false, true)
46		doc.Save(output, SDFDoc::E_linearized)
47	end
48end
49
50	# Relative path to the folder containing the test files.
51	input_path = "../../TestFiles/"
52	output_path = "../../TestFiles/Output/"
53	
54	PDFNet.Initialize(PDFTronLicense.Key)
55	
56	vec = [Redaction.new(1, Rect.new(100, 100, 550, 600), false, "Top Secret"),
57		Redaction.new(2, Rect.new(30, 30, 450, 450), true, "Negative Redaction"),
58		Redaction.new(2, Rect.new(0, 0, 100, 100), false, "Positive"),
59		Redaction.new(2, Rect.new(100, 100, 200, 200), false, "Positive"),
60		Redaction.new(2, Rect.new(300, 300, 400, 400), false, ""),
61		Redaction.new(2, Rect.new(500, 500, 600, 600), false, ""),
62        Redaction.new(3, Rect.new(0, 0, 700, 20), false, "")]
63
64    app = Appearance.new
65    app.RedactionOverlay = true
66    app.Border = false
67    app.ShowRedactedContentRegions = true
68	
69    Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app)
70	PDFNet.Terminate
71	puts "Done..."
1'
2' Copyright (c) 2001-2024 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 PDFRedactTestVB
15    Dim pdfNetLoader As PDFNetLoader
16    Sub New()
17        pdfNetLoader = pdftron.PDFNetLoader.Instance()
18    End Sub
19
20    ' PDF Redactor is a separately licensable Add-on that offers options to remove 
21    ' (not just covering or obscuring) content within a region of PDF. 
22    ' With printed pages, redaction involves blacking-out or cutting-out areas of 
23    ' the printed page. With electronic documents that use formats such as PDF, 
24    ' redaction typically involves removing sensitive content within documents for 
25    ' safe distribution to courts, patent and government institutions, the media, 
26    ' customers, vendors or any other audience with restricted access to the content. 
27    '
28    ' The redaction process in PDFNet consists of two steps:
29    ' 
30    '  a) Content identification: A user applies redact annotations that specify the 
31    ' pieces or regions of content that should be removed. The content for redaction 
32    ' can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
33    ' as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
34    ' or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
35    ' can see, move and redefine these annotations.
36    '  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
37    ' PDFNet to apply the redact regions, after which the content in the area specified 
38    ' by the redact annotations is removed. The redaction function includes number of 
39    ' options to control the style of the redaction overlay (including color, text, 
40    ' font, border, transparency, etc.).
41    ' 
42    ' PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
43    ' is contained in a redaction region, that portion of the image or path data is 
44    ' destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
45    ' be used to review and remove metadata and other content that can exist in a PDF 
46    ' document, including XML Forms Architecture (XFA) content and Extensible Metadata 
47    ' Platform (XMP) content.
48    '
49    ' The following sample illustrates how to redact a PDF document using 'pdftron.PDF.Redactor'.
50    Sub Main()
51        PDFNet.Initialize(PDFTronLicense.Key)
52
53        Dim input_path As String = "../../../../TestFiles/"
54        Dim output_path As String = "../../../../TestFiles/Output/"
55        Dim input_filename As String = "newsletter.pdf"
56
57        Try
58            Dim rarr As ArrayList = New ArrayList
59            rarr.Add(New Redactor.Redaction(1, New Rect(100, 100, 550, 600), False, "Top Secret"))
60            rarr.Add(New Redactor.Redaction(2, New Rect(30, 30, 450, 450), True, "Negative Redaction"))
61            rarr.Add(New Redactor.Redaction(2, New Rect(0, 0, 100, 100), False, "Positive"))
62            rarr.Add(New Redactor.Redaction(2, New Rect(100, 100, 200, 200), False, "Positive"))
63            rarr.Add(New Redactor.Redaction(2, New Rect(300, 300, 400, 400), False, ""))
64            rarr.Add(New Redactor.Redaction(2, New Rect(500, 500, 600, 600), False, ""))
65            rarr.Add(New Redactor.Redaction(3, New Rect(0, 0, 700, 20), False, ""))
66
67
68            Dim app As Redactor.Appearance = New Redactor.Appearance()
69            app.RedactionOverlay = True
70            app.Border = False
71            app.ShowRedactedContentRegions = True
72
73            Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", rarr, app)
74
75            Console.WriteLine("Done...")
76        Catch ex As PDFNetException
77            Console.WriteLine(ex.Message)
78        Catch ex As Exception
79            MsgBox(ex.Message)
80        End Try
81        PDFNet.Terminate()
82    End Sub
83
84    Sub Redact(ByVal input As String, ByVal output As String, ByVal rarr As ArrayList, ByVal app As Redactor.Appearance)
85        Try
86            Using doc As PDFDoc = New PDFDoc(input)
87                doc.InitSecurityHandler()
88
89                Redactor.Redact(doc, rarr, app, False, True)
90                doc.Save(output, SDFDoc.SaveOptions.e_linearized)
91            End Using
92        Catch ex As PDFNetException
93            Console.WriteLine(ex.Message)
94        Catch ex As Exception
95            MsgBox(ex.Message)
96        End Try
97    End Sub
98
99End Module
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales