foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.85k stars 1.15k forks source link

Access permissions are not applied to PDF if pdfVersion is "1.7ext3". #1125

Closed adrift2000 closed 4 years ago

adrift2000 commented 4 years ago

Bug Report

Description of the problem

Access permissions are not applied to PDF if pdfVersion is "1.7ext3".

Code sample

const PDFDocument = require('pdfkit');
const fs = require('fs');

var doc = new PDFDocument({
    userPassword: '11',
    ownerPassword: '22',
    pdfVersion: '1.7ext3',
    permissions: {
        printing: 'highResolution',
        modifying: true,
        copying: true,
        annotating: true,
        fillingForms: true,
        contentAccessibility: true,
        documentAssembly: true
    }
});

doc.pipe(fs.createWriteStream('output.pdf'));

doc.text('Hello!');

doc.end();

Open the document in Acrobat/Acrobat Reader, enter the user password, then view the "Document Restrictions Summary" list: all the permissions are marked as "Not Allowed".

The issue occurs only if pdfVersion is "1.7ext3".

Your environment

adrift2000 commented 4 years ago

I've found the problem, there is a typo in lib/security.js, in _setupEncryptionV5 function:

const permissions = getPermissionsR3(options);

It should be:

const permissions = getPermissionsR3(options.permissions);
liborm85 commented 4 years ago

Can you please create a pull request?

adrift2000 commented 4 years ago

Done