HummusJS
HummusJS copied to clipboard
Flatten PDF Form after filling
Hi, I've been trying to figure out how to flatten a pdf form after filling it. I'm currently using the example code that you supplied for filling forms. Is it possible to do this with hummusJS and if so how would i go about it?
What does "flatten" a pdf form mean?
Rather then rendering the text into the interactive form fields, remove the fields and render plain text instead
Oh. Ok. Never trird it, but i assume that this has to do with deleting the acroform object from the catalog object (in other words, modifying the catalog object to have all keys/values but acroform). It might also mean turning the field annotations to actual placement on the page.
You will need the modification interface of hummus, and to track the acroform, both have example in the form filling code
Crappy, but working : https://gist.github.com/Ghostfly/2988e59d9c2b6ca42330d96796aa01ed (edit: uncrappyfied a bit)
actually i wrote a solution back then that you may want to use: https://github.com/galkahana/HummusJSSamples/tree/lock-form/lock-form
@galkahana I tried using the lock-form sample script you provided and I'm getting an error with my test file however it works fine with your sample file:
TypeError: wrong arguments, pass 1 argument which is a valid index in the array at lockWidgetAnnotationsForPage (/Users/pdf_fill/utils/pdf_form_lock.js:220:63)
This is the file I'm testing it on: 1099_copy_a_2018 3.pdf
It seems that the link provided above has been moved to: https://github.com/galkahana/HummusJSSamples/tree/master/lock-form
@tjshipe I am also getting the same error. I think it's a bug on line 217. @galkahana Could you confirm that it should be changed from:
for(var i = 0; i < annotationsArray.getLength();++i) {
...
}
to:
for(var i = 0; i < contentsArray.getLength();++i) {
...
}
I use it together with fill form, but all the filled content gets deleted when I call lock. Any ideas what could be the cause?