Scheduled Maintenance
-
February 10, 2026, from 8:00 AM to 9:00 AM PST. Account-related operations might be temporarily unavailable.

Redact document

Requirements
View Demo

Sample JavaScript code for using Apryse Web 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.

Learn more about our Web SDK.

Implementation steps

To redact documents with WebViewer:

Step 1: Follow get started in your preferred web stack for WebViewer
Step 2: Add the sample code provided in this guide

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6(exports => {
7 exports.runPDFRedactTest = () => {
8 const PDFNet = exports.Core.PDFNet;
9
10 const main = async () => {
11 // Relative path to the folder containing test files.
12 const inputPath = '../TestFiles/';
13 try {
14 const doc = await PDFNet.PDFDoc.createFromURL(inputPath + 'newsletter.pdf');
15 doc.initSecurityHandler();
16 doc.lock();
17
18 const redactionArray = []; // we will contain a list of redaction objects in this array
19 redactionArray.push(await PDFNet.Redactor.redactionCreate(1, await PDFNet.Rect.init(100, 100, 550, 600), false, 'Top Secret'));
20 redactionArray.push(await PDFNet.Redactor.redactionCreate(2, await PDFNet.Rect.init(30, 30, 450, 450), true, 'Negative Redaction'));
21 redactionArray.push(await PDFNet.Redactor.redactionCreate(2, await PDFNet.Rect.init(0, 0, 100, 100), false, 'Positive'));
22 redactionArray.push(await PDFNet.Redactor.redactionCreate(2, await PDFNet.Rect.init(100, 100, 200, 200), false, 'Positive'));
23 redactionArray.push(await PDFNet.Redactor.redactionCreate(2, await PDFNet.Rect.init(300, 300, 400, 400), false, ''));
24 redactionArray.push(await PDFNet.Redactor.redactionCreate(2, await PDFNet.Rect.init(500, 500, 600, 600), false, ''));
25 redactionArray.push(await PDFNet.Redactor.redactionCreate(3, await PDFNet.Rect.init(0, 0, 700, 20), false, ''));
26
27 const blue = await PDFNet.ColorPt.init(0.1, 0.2, 0.6, 0);
28 const timesFont = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_roman);
29 const appear = { redaction_overlay: true, positive_overlay_color: blue, border: false, font: timesFont, show_redacted_content_regions: true };
30 PDFNet.Redactor.redact(doc, redactionArray, appear, false, false);
31
32 const docbuf = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_linearized);
33 saveBufferAsPDFDoc(docbuf, 'redacted.pdf');
34 console.log('Done...');
35 } catch (err) {
36 console.log(err.stack);
37 }
38 };
39 // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
40 PDFNet.runWithCleanup(main);
41 };
42})(window);
43// eslint-disable-next-line spaced-comment
44//# sourceURL=PDFRedactTest.js

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales