Smart redaction API guide: Securely redact sensitive data in documents
This guide covers how to use the smart redaction feature in the Document Converter API to identify and redact sensitive information such as credit card numbers, email addresses, phone numbers, and more. Protect your documents efficiently while maintaining compliance with security standards.
What is smart redaction?
Smart redaction enables you to automatically locate and redact predefined sensitive data types within documents. Customize redaction settings to meet your specific security and privacy needs.
Smart redaction properties
The Nutrient API offers a comprehensive set of properties for smart redaction. These options allow you to specify the types of sensitive information to redact and customize the output format, ensuring your documents meet compliance and security standards.
With these properties, you can fully customize how sensitive information is handled, whether redacting specific data types or applying configurations like custom colors.
Property | Description |
---|---|
RedactCreditCardNumbers |
Specifies whether credit card numbers will be redacted. |
RedactEmailAddresses |
Specifies whether email addresses will be redacted. |
RedactIBANs |
Specifies whether IBANs will be redacted. |
RedactPhoneNumbers |
Specifies whether phone numbers will be redacted. |
RedactURIs |
Specifies whether URIs will be redacted. |
RedactVATIDs |
Specifies whether VAT IDs will be redacted. |
RedactVehicleIdentificationNumbers |
Specifies whether vehicle identification numbers will be redacted. |
RedactSocialSecurityNumbers * |
Specifies whether social security numbers will be redacted. |
RedactPostalAddresses * |
Specifies whether postal addresses will be redacted. |
MarkColor |
The color used to cover redacted information. |
Dictionaries |
List of language codes, linked by ‘+’. For example: ”ENG+FRA” |
DetectOrientation |
Specifies whether orientation will be detected automatically. |
PageRange _ |
Range of pages to redact; use “_” for all pages. |
Note that properties marked with * are future upgrades.
Document Converter service client sample code
The sample code for smart redaction uses the OpenService
and CloseService
methods from Document Converter service client sample code:
/// <summary> /// Configure the bindings and endpoints and open the service using the specified address. /// </summary> /// <param name="address">URL of the endpoint.</param> /// <returns>An instance of the Web Service.</returns> public static DocumentConverterServiceClient OpenService(string address) { DocumentConverterServiceClient client = null; try { BasicHttpBinding binding = new BasicHttpBinding(); // Use standard Windows Security. binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; // Increase the client timeout to deal with (very) long running requests. binding.SendTimeout = TimeSpan.FromMinutes(120); binding.ReceiveTimeout = TimeSpan.FromMinutes(120); // Set the maximum document size to 50MB. binding.MaxReceivedMessageSize = 50 * 1024 * 1024; binding.ReaderQuotas.MaxArrayLength = 50 * 1024 * 1024; binding.ReaderQuotas.MaxStringContentLength = 50 * 1024 * 1024; EndpointAddress epa = new EndpointAddress(new Uri(address)); client = new DocumentConverterServiceClient(binding, epa); client.OpenAsync(); return client; } catch (Exception) { CloseService(client); throw; } } /// <summary> /// Check if the client is open and then close it. /// </summary> /// <param name="client">The client to close.</param> public static void CloseService(DocumentConverterServiceClient client) { if (client != null && client.State == CommunicationState.Opened) client.CloseAsync().GetAwaiter().GetResult(); }
Example: Implementing smart redaction with the API
This example demonstrates how to use the API to redact credit card numbers and email addresses in a specific page range:
/// <summary> /// Perform smart redaction on the supplied file, writing the result into the target folder. /// </summary> /// <param name="ServiceURL">URL endpoint for the PDF Converter service.</param> /// <param name="sourceFileName">Source filename.</param> /// <param name="targetFolder">Target folder to receive the output file.</param> static void SmartRedaction(string ServiceURL, string sourceFileName, string targetFolder) { DocumentConverterServiceClient client = null; try { // Create minimum `OpenOptions` object. OpenOptions openOptions = new OpenOptions(); openOptions.OriginalFileName = Path.GetFileName(sourceFileName); // Create minimum `SmartRedactionSettings`. SmartRedactionSettings smartRedactionSettings = new SmartRedactionSettings(); smartRedactionSettings = new SmartRedactionSettings(); // Set what needs to be redacted. smartRedactionSettings.RedactCreditCardNumbers = BooleanEnum.True; smartRedactionSettings.RedactEmailAddresses = BooleanEnum.True; smartRedactionSettings.RedactPhoneNumbers = BooleanEnum.True; // Create target folder if required. if (!Directory.Exists(targetFolder)) { Directory.CreateDirectory(targetFolder); } // ** Read the source file into a byte array. byte[] sourceFile = File.ReadAllBytes(sourceFileName); // ** Open the service and configure the bindings. client = OpenService(ServiceURL); // ** Carry out the conversion. byte[] result = client.SmartRedaction(sourceFile, openOptions, smartRedactionSettings); // ** Save the results. if (result != null) { if (!Directory.Exists(targetFolder)) { Directory.CreateDirectory(targetFolder); } string filename = Path.GetFileNameWithoutExtension(sourceFileName); string destinationFileName = Path.GetFullPath(Path.Combine(targetFolder, filename + "-redacted.pdf")); using (FileStream fs = File.Create(destinationFileName)) { fs.Write(result, 0, result.Length); fs.Close(); } Console.WriteLine("File converted to " + destinationFileName); } else { Console.WriteLine("Nothing returned"); } } catch (FaultException<WebServiceFaultException> ex) { Console.WriteLine($"FaultException occurred: ExceptionType: {ex.Detail.ExceptionType.ToString()}"); Console.WriteLine(); Console.WriteLine($"Error Detail: {string.Join(Environment.NewLine, ex.Detail.ExceptionDetails)}"); Console.WriteLine($"Error message: {ex.Message}"); Console.WriteLine(); Console.WriteLine($"Error reason: {ex.Reason}"); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Data.ToString()); } finally { if (client != null) { CloseService(client); } } }
Why use smart redaction?
-
Save time and resources — Automate complex redaction tasks, eliminating manual effort.
-
Ensure data security — Protect sensitive information from unauthorized access.
-
Achieve compliance — Meet industry standards for data privacy and protection.
-
Enhance accuracy — Rely on intelligent detection for precise redaction of sensitive details.