You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to decrypt an encrypted pdf, providing its password, I encounter the following error-
Input document to PDFDocument.load is encrypted. You can use PDFDocument.load(..., { ignoreEncryption: true }) if you wish to load the document anyways.
The thing is that I don't want to set ignoreEncryption to true.
Please help, this is the code :
import fs from 'fs';
import { PDFDocument } from 'pdf-lib';
async function decryptPdf() {
try {
const inputFile = './encrypted.pdf'; // Path to the encrypted PDF
const password = '2507'; // Password to decrypt
const outputFile = './decrypted.pdf'; // Path to save the decrypted PDF
// Read the encrypted PDF
const encryptedPdfBytes = fs.readFileSync(inputFile);
// Load the PDF with the password
const pdfDoc = await PDFDocument.load(encryptedPdfBytes, { password });
// Save the decrypted PDF
const decryptedPdfBytes = await pdfDoc.save();
fs.writeFileSync(outputFile, decryptedPdfBytes);
console.log(`Decryption successful! File saved at: ${outputFile}`);
} catch (error) {
if (error.message.includes('Invalid Password')) {
console.error('Decryption failed: Invalid password.');
} else {
console.error(`An error occurred: ${error.message}`);
}
}
}
decryptPdf();
The text was updated successfully, but these errors were encountered:
This issue is stale because it has been open 2 weeks with no activity. It will be closed in 2 days unless there is new activity. See MAINTAINERSHIP.md#issues for details.
When I try to decrypt an encrypted pdf, providing its password, I encounter the following error-
Input document to
PDFDocument.load
is encrypted. You can usePDFDocument.load(..., { ignoreEncryption: true })
if you wish to load the document anyways.The thing is that I don't want to set ignoreEncryption to true.
Please help, this is the code :
import fs from 'fs';
import { PDFDocument } from 'pdf-lib';
async function decryptPdf() {
try {
const inputFile = './encrypted.pdf'; // Path to the encrypted PDF
const password = '2507'; // Password to decrypt
const outputFile = './decrypted.pdf'; // Path to save the decrypted PDF
}
decryptPdf();
The text was updated successfully, but these errors were encountered: