The easiest way to securely transfer your PDF is to serve it through HTTPS. This way, the browser will take care of decrypting the secured communication for you.

Additionally, you can encrypt the PDF’s content on the server using your own custom encryption. When you fetch the encrypted PDF, decrypt the data in the browser into an ArrayBuffer. Then pass it to Nutrient’s load method, and it’ll render your document (try it in the Playground(opens in a new tab)):

NutrientViewer.load({
container: "#pspdfkit",
document: myDecryptedArrayBuffer
})
.then((instance) => {
console.log("Decrypted document loaded successfully");
})
.catch((error) => {
console.error("Failed to load document:", error.message);
});

Complete decryption example

Below is a complete example showing how to fetch an encrypted PDF, decrypt it, and load it in the viewer:

async function loadEncryptedPDF(encryptedUrl, decryptionKey) {
try {
// Fetch the encrypted PDF
const response = await fetch(encryptedUrl);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
const encryptedData = await response.arrayBuffer();
// Decrypt the data using your custom decryption logic
const decryptedArrayBuffer = await decrypt(encryptedData, decryptionKey);
// Load the decrypted PDF
const instance = await NutrientViewer.load({
container: "#pspdfkit",
document: decryptedArrayBuffer
});
console.log("Encrypted document loaded successfully");
return instance;
} catch (error) {
console.error("Failed to load encrypted document:", error.message);
throw error;
}
}