galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.14k stars 169 forks source link

createWriterToModify ignores options object #216

Open hdkeeper opened 6 years ago

hdkeeper commented 6 years ago

Hi there. I'm trying to use HummusJS to fill and lock a PDF form blank. But it seems that hummus.createWriterToModify() totally ignores the 3rd argument -- an options object.

The form fields are filled correctly, but the resulting PDF stays unprotected, although it should. Am I missing some point? Consider the sample code below.

let pdfWriter = hummus.createWriterToModify(
    new hummus.PDFRStreamForFile('blank.pdf'),
    new hummus.PDFStreamForResponse(res),
    {
        userPassword: '',
        ownerPassword: 'bbbbb',
        userProtectionFlag: 4
});
chunyenHuang commented 6 years ago

How about try to add password?

galkahana commented 6 years ago

You need to put a user password. Dont leave it empty.

galkahana commented 6 years ago

Oh. Now i see what you are trying to do. Providing a password to modify only means that the password is used for reading the original pdf. It doesnt add password. If you want to turn an unprotectrd document to one thats protected, use hummus.recrypt. And make sure to provide a user password

hdkeeper commented 6 years ago

So I have to process my document with two passes. At the first pass I fill form fields etc. At the second pass I should use hummus.recrypt() on the document obtained from the first pass.

michaelktree commented 5 years ago

Hi @hdkeeper, I'm trying to do the same thing. Did you manage to make this work? It seems that the document obtained from the first pass is not released until the session is over Thanks