Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying a password-protected PDF with text changes (StartCopyingContext error) #185

Open
thmclellan opened this issue Jun 5, 2020 · 0 comments
Labels

Comments

@thmclellan
Copy link

First off - thank you John for this amazing library! It's made Hummus much easier.

I'm trying to add text to an existing PDF that is protected with a user password and leave the password protection in place while making changes.

Everything goes well until I call endPDF(), which triggers the following error:

TypeError: unable to create copying context. verify that the target is an existing PDF file

The hummus-error.log says this:

PDFDocumentHandler::StartCopyingContext, Cant decrypt document. make sure to provide appropriate password for this document in order to copy from it

It seems the error happens when endPDF() calls this._writeInfo(), which calls hummus's writer.createPDFCopyingContext(), an older Hummus function that doesn't seem to accept a password.

this._writeInfo();

const copyCtx = this.writer.createPDFCopyingContext(copyFrom);

For my own purposes, when I comment out the writeInfo call, everything seems to work okay, but I'm guessing writeInfo may be important for other use cases.

In a future update, would it make sense to make the writeInfo step optional somehow? (e.g. as an option when calling endPDF or when instantiating HummusRecipe). Or maybe there's an easier way that I'm not seeing. In any case, I wanted to capture the issue and the potential workaround.

Here is a sample PDF file with user password '123123' for testing: https://www.dropbox.com/s/vcodzkyv5s67mp3/pdf-with-password-123123.pdf?dl=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants