Tutorial

How to Redact Documents (PDF, JPG, PNG) using JavaScript

Learn how to redact documents using Eden AI’s OCR Anonymization API in JavaScript. Learn how to set up Axios, launch an async redaction job, retrieve the results, interpret the output, and manage optional job actions like listing and deleting.

How to Redact Documents (PDF, JPG, PNG) using JavaScript
TABLE OF CONTENTS

Protecting sensitive information is essential in fields such as healthcare, legal services, and finance. Document anonymization, also known as Document Redaction, helps ensure that confidential data stays secure.

Eden AI offers an asynchronous OCR anonymization API that simplifies this task. In this guide, you’ll learn how to automate document redaction in JavaScript using Eden AI’s API, following a straightforward two-step process.

What is Document Redaction?

Document redaction, or Anonymization, involves concealing or removing sensitive details like names, dates, or ID numbers from documents.

This process safeguards privacy and helps organizations stay compliant with data protection laws by rendering confidential information inaccessible or hidden.

How to Redact Documents

Set Up Your Eden AI Account

1. Create an account: If you don't have an Eden AI account, sign up for free with the following link. Then get your API key in the API Keys section, which you can use to access various AI services.

2. Access Document Parsing Tools: Once logged in, go to the document parsing section of the platform.

3. Choose the Document Redaction Feature: Select the Document Redaction tool. You can also explore other OCR tools.

Implementing Document Redaction in Python

The process is asynchronous to allow for better performance and scalability. Redacting a document can take time, especially for large files, so:

  • The POST request initiates the task and returns a job ID.
  • The GET request lets you check when the job is complete and retrieve the final redacted result once it's ready.

Step 1: Install Axios for HTTP Requests

To make requests to the Eden AI API in JavaScript, you'll need the axios package.

Install it using npm:


npm install axios

Step 2: Launch the Redaction Job (POST Request)

Eden AI handles redaction in two phases:

  • The POST request launches the redaction job asynchronously.
  • The GET request retrieves the result once the job is processed.

Here’s how to send the POST request:


const axios = require('axios');

const headers = {
  Authorization: 'Bearer {API_TOKEN}', // Replace with your Eden AI API token
};

const url = 'https://api.edenai.run/v2/ocr/anonymization_async';

const jsonPayload = {
  providers: 'readyredact',
  file_url: 'https://your-image-url.com/document.jpg', // Replace with your document URL
};

axios.post(url, jsonPayload, { headers })
  .then(response => {
    console.log(response.data); // This will return a job_id
  })
  .catch(error => {
    console.error(error);
  });

Explanation:

  • Authorization: Your API token from Eden AI.
  • file_url: The public URL of the image or document you want to redact.
  • providers: "readyredact" is the current provider supported for this feature.

The response will include a job_id, which you'll use in the next step.

Step 3: Retrieve Redaction Results (GET Request)

Use the job_id returned from the POST request to retrieve the redacted document and check job status:


const axios = require('axios');

const headers = {
  Authorization: 'Bearer {API_TOKEN}' // Replace with your token
};

const publicId = 'your_job_id_here'; // Replace with actual job_id
const url = `https://api.edenai.run/v2/ocr/anonymization_async/${publicId}/`;

axios.get(url, { headers })
  .then(response => {
    console.log(response.data); // Redaction result
  })
  .catch(error => {
    console.error(error);
  });

Example Output:


{
  "status": "finished",
  "redacted_document_url": "https://edenai-redacted.s3.amazonaws.com/filename.pdf",
  "entities_found": [
    {
      "entity": "name",
      "value": "John Doe",
      "position": {...}
    }
  ]
}

  • status: Indicates if the job is done.
  • redacted_document_url: Link to download the final redacted file.
  • entities_found: List of redacted items and their metadata.

Managing Redaction Jobs

In addition to launching and retrieving results from redaction jobs, Eden AI also provides optional endpoints for better job management:

  1. List All Redaction Jobs
    Endpoint: GET https://api.edenai.run/v2/ocr/anonymization_async/
    Use this to retrieve a list of all launched redaction jobs. It’s helpful for tracking job statuses or fetching results later using their job IDs.
    You can check the documentation here.

  2. Delete Redaction Jobs
    Endpoint: DELETE https://api.edenai.run/v2/ocr/anonymization_async/
    This allows you to delete redaction jobs from your account once you’ve retrieved the results, helping you keep your job history clean and organized.
    You can check the documentation here.

Why Eden AI is the Best Tool for Document Redaction

Eden AI provides several advantages.

Multiple AI Providers

Choose from a variety of AI services and providers, making it easy to compare outputs and select the most effective solution for your use case.

Easy Integration

Access multiple AI tools through a single API key, eliminating the need for separate integrations. Simplify your setup and accelerate your launch.

Cost Efficiency

With a pay-as-you-go approach, you only pay for what you use. There are no upfront fees, giving you flexible and scalable access to powerful AI services.

Conclusion

With Eden AI and JavaScript, redacting documents becomes simple, secure, and scalable. Whether you need to anonymize sensitive data for legal, medical, or enterprise purposes, Eden AI offers a powerful toolset to get the job done in minutes.

Try it out today and secure your data with ease.

You can access the full documentation for Document Redaction here.

Start Your AI Journey Today

  • Access 100+ AI APIs in a single platform.
  • Compare and deploy AI models effortlessly.
  • Pay-as-you-go with no upfront fees.
Start building FREE

Related Posts

Try Eden AI for free.

You can directly start building now. If you have any questions, feel free to chat with us!

Get startedContact sales
X

Start Your AI Journey Today

Sign up now with free credits to explore 100+ AI APIs.
Get my FREE credits now