Skip to content

Unlock - Decrypt - Password Remove #64

@zairlaka

Description

@zairlaka

Even if I've given the correct password its still failed to unlock that pdf
because it require
PermissionDeniedError: requires owner access or modify permission

const pdfBytes = base64ToUint8Array(file.content);

      const pdf = await PDF.load(pdfBytes, { credentials: password });

      if (pdf.isEncrypted && !pdf.isAuthenticated) {
        message.error(t("unlock_pdf.incorrect_password"));
        return;
      }
file:///Users/zairomer/Desktop/ror/pdf-editify/node_modules/@libpdf/core/dist/index.mjs:42068
                if (!handler.hasOwnerAccess && !handler.permissions.modify) throw new PermissionDeniedError("Cannot remove protection: requires owner access or modify permission", "modify");
                                                                                  ^

PermissionDeniedError: Cannot remove protection: requires owner access or modify permission
    at PDF.removeProtection (file:///Users/zairomer/Desktop/ror/pdf-editify/node_modules/@libpdf/core/dist/index.mjs:42068:69)
    at run (file:///Users/zairomer/Desktop/ror/pdf-editify/statement.mjs:16:7) {
  code: 'PERMISSION_DENIED',
  requiredPermission: 'modify'
}

here is the stand alone file statement.mjs

import { readFile, writeFile } from "fs/promises";
import { PDF } from "@libpdf/core";

const inputPath = "statement.pdf";
const outputPath = "output.pdf";
const password = "35286"; // change this

const run = async () => {
  const bytes = await readFile(inputPath);

  const pdf = await PDF.load(bytes, {
    credentials: password,
  });
  console.log("PDF Security: 🔻", pdf.security); // output 'undefined'

  pdf.removeProtection();

  await writeFile(outputPath, await pdf.save());

  console.log("PDF decrypted successfully!");
};

run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions