Smart redaction API guide: Securely redact sensitive data in documents

This guide explains 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. You can customize the 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 such as custom colors.

Property Description
RedactCreditCardNumbers Specifies whether credit card numbers will be redacted.
RedactEmailAddresses Specifies whether email addresses will be redacted.
RedactIBANs Specifies whether International Bank Account Numbers (IBANs) will be redacted.
RedactPhoneNumbers Specifies whether phone numbers will be redacted.
RedactURIs Specifies whether Uniform Resource Identifier (URIs) will be redacted.
RedactVATIDs Specifies whether Value-Added Tax (VAT) IDs will be redacted.
RedactVehicleIdentificationNumbers Specifies whether vehicle identification numbers 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.

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);

                }
            }

        }

For a practical demonstration, refer to the sample code for smart redaction.

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.