It’s possible to apply redaction operations without the need to present any user interface (UI) to the user.

Standalone

In Standalone mode of Nutrient Web SDK, you can perform the operation using JavaScript in the browser by setting the headless option as true when loading the JavaScript library. This indicates you don’t want a UI:

NutrientViewer.load({
// ...
headless: true
})
.then((instance) => {
// Apply your operations.
})
.catch((error) => {
console.error("Failed to load viewer:", error.message);
});

Once the SDK is loaded, you can apply any of our operations as normal.

Server-backed

When using the Server-backed operational mode, a variety of operations are available server-side. See the Document Engine documentation for additional information.

Complete headless example

Redact all Social Security numbers without showing the UI:

NutrientViewer.load({
document: "document.pdf",
headless: true
})
.then(async (instance) => {
// Search and create redaction annotations.
const ids = await instance.createRedactionsBySearch(
NutrientViewer.SearchPattern.SOCIAL_SECURITY_NUMBER,
{ searchType: NutrientViewer.SearchType.PRESET }
);
if (ids.length > 0) {
console.log(`Found ${ids.length} SSNs to redact`);
await instance.applyRedactions();
const pdf = await instance.exportPDF();
// Save or send the redacted PDF.
} else {
console.log("No SSNs found in document");
}
})
.catch((error) => {
console.error("Redaction failed:", error.message);
});