Sample C# 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 UWP SDK.
1//
2// Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
3//
4
5using System;
6using System.Collections.Generic;
7using System.IO;
8using System.Threading.Tasks;
9using Windows.Foundation;
10
11using pdftron.PDF;
12using pdftron.SDF;
13
14using PDFNetUniversalSamples.ViewModels;
15
16namespace PDFNetSamples
17{
18 public sealed class PDFRedactTest : Sample
19 {
20 public PDFRedactTest() :
21 base("PDFRedact", "PDF Redactor is a separately licensable Add-on that offers options to remove (not just covering or obscuring) content within a region of PDF. ")
22 {
23 }
24
25 public override IAsyncAction RunAsync()
26 {
27 return Task.Run(new System.Action(async () => {
28 WriteLine("--------------------------------");
29 WriteLine("Starting PDFRedact Test...");
30 WriteLine("--------------------------------\n");
31
32 try
33 {
34 IList<RedactorRedaction> rarr = new List<RedactorRedaction>();
35 rarr.Add(new RedactorRedaction(1, new pdftron.PDF.Rect(0, 0, 600, 600), true, "Top Secret"));
36 rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(30, 30, 550, 550), true, "Top Secret"));
37 rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(100, 100, 200, 200), false, "bar"));
38 rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(300, 300, 400, 400), false, ""));
39 rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(500, 500, 600, 600), false, ""));
40 rarr.Add(new RedactorRedaction(3, new pdftron.PDF.Rect(0, 0, 700, 20), false, ""));
41 string output_file_path = Path.Combine(OutputPath, "redacted.pdf");
42 await RedactAsync(Path.Combine(InputPath, "newsletter.pdf"), output_file_path, rarr);
43 }
44 catch (Exception e)
45 {
46 WriteLine(e.Message);
47 }
48
49 WriteLine("\n--------------------------------");
50 WriteLine("Done PDFRedact Test.");
51 WriteLine("--------------------------------\n");
52 })).AsAsyncAction();
53 }
54
55 async Task RedactAsync(string input, string output, IList<RedactorRedaction> rarr)
56 {
57 using (PDFDoc doc = new PDFDoc(input))
58 {
59 doc.InitSecurityHandler();
60
61 RedactorAppearance app = new RedactorAppearance();
62 //app.Font = new System.Drawing.Font("Arial", 12);
63 app.PositiveOverlayColor = Windows.UI.Colors.Red;
64 app.NegativeOverlayColor = Windows.UI.Colors.WhiteSmoke;
65
66 string output_file_path = Path.Combine(OutputPath, "redacted.pdf");
67 Redactor.Redact(doc, rarr, app);
68 await doc.SaveAsync(output_file_path, SDFDocSaveOptions.e_linearized);
69 WriteLine("Result of redaction saved in " + output_file_path);
70 await AddFileToOutputList(output_file_path).ConfigureAwait(false);
71 }
72 }
73 }
74}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales