PDFRedaction

Sample JavaScript 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. Learn more about our Web SDK.

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