Process documents via Document Engine or DWS API using JavaScript
Nutrient Web SDK supports editing PDF documents directly in a browser. However, some use cases require delegating processing tasks to more powerful and feature-rich Nutrient backends:
-
Document Engine — Deployable as either a self-hosted solution or a managed service by Nutrient.
-
Nutrient DWS API — A managed document processing API.
For your convenience, the Web SDK integrates seamlessly with Nutrient backends, acting as their client through an intuitive JavaScript API. Using these backends allows you to perform all document processing operations supported by the Web SDK, plus additional features such as HTML-to-PDF conversion or OCR. All Nutrient backend options offer equivalent feature sets, ensuring easy migration between them without extensive changes to your frontend code if your requirements evolve.
This guide will help you get started using Nutrient Web SDK to perform document processing via Nutrient backends.
Processing documents via the build API
Nutrient Web SDK enables document editing, conversion, OCR, and other advanced operations.
To process a document using Nutrient Web SDK, you’ll need:
-
An access token — A JWT token used to authorize backend access. Refer to the authorization section for your backend below.
-
Build instructions — Defines the operations to perform. You can find the schema in the API reference, with more specific examples available on our DWS API tools pages.
-
Inputs — Required inputs for the processing operation.
To execute a build request, pass these arguments to the PSPDFKit.build
method. For example:
// Inputs must be provided as `ArrayBuffer` or `Blob` objects. const document = (await fetch("/url-to-your-document.pdf")).blob(); // Perform the processing via the DWS API. const processedDocument = await PSPDFKit.build( // Authorization token for the DWS API. { jwt: accessToken }, // Instructions for the processing request. { parts: [ // Apply OCR to the first input and use it as the first part of the final document. { file: "document", actions: [ { type: "ocr", language: "english" } ] }, // Use a sample DOCX document served from a URL as the second part of the final document. // Note: Inputs served from URLs do not need to be provided in the `inputs` argument. { file: { url: "https://www.nutrient.io/api/downloads/samples/docx/document.docx" } } ] }, // Inputs required for the request, uploaded alongside the instructions. [{ name: "document", content: document }] );
Document Engine authorization
To use Document Engine as your processing backend, authenticate client requests using a JSON Web Token (JWT). This JWT must include the required claims, as detailed in our JWT authorization reference.
For example, the following JWT grants access to Document Engine’s document editing and Office conversion API from the origin example.com
:
{ "server_url": "your-document-engine-url", "allowed_operations": [ "document_editor_api", "office_conversion_api" ], "allowed_origins": ["example.com"], ...rest_of_jwt_claims }
DWS API authorization
To use DWS API as your processing backend, authenticate client requests with access tokens generated via DWS API:
-
Create an account or log in to your existing account on the DWS API website to obtain an API key.
-
Generate a JWT using your API key through the
POST tokens
endpoint. For instance, the following request creates a token that permits document editing and Office conversion from the originexample.com
, expiring in 1 hour (3,600 seconds):
curl -X POST https://api.nutrient.io/tokens \ -H 'Authorization: Bearer pdf_live_<rest_of_your_api_key>' \ -H "Content-Type: application/json" \ -d '{ "allowedOperations": [ "document_editor_api", "office_conversion_api" ], "allowedOrigins": [ "example.com" ], "expirationTime": 3600 }'
-
Retrieve the
accessToken
from the response:
{ "accessToken": "<created_access_token>", "id": "<access_token_id>" }
Additional resources
If you want to perform the processing on your backend, use the public APIs of the respective Nutrient backend:
-
For detailed guides on deploying and using Document Engine, see the Document Engine guides.
-
To explore and integrate DWS API, visit the Nutrient DWS API website.