HummusJS icon indicating copy to clipboard operation
HummusJS copied to clipboard

Flatten PDF Form after filling

Open bevbomb opened this issue 7 years ago • 8 comments

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?

bevbomb avatar Jul 24 '17 07:07 bevbomb

What does "flatten" a pdf form mean?

galkahana avatar Jul 24 '17 15:07 galkahana

Rather then rendering the text into the interactive form fields, remove the fields and render plain text instead

bevbomb avatar Jul 24 '17 22:07 bevbomb

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

galkahana avatar Jul 25 '17 04:07 galkahana

Crappy, but working : https://gist.github.com/Ghostfly/2988e59d9c2b6ca42330d96796aa01ed (edit: uncrappyfied a bit)

m1m1s1ku avatar May 23 '18 00:05 m1m1s1ku

actually i wrote a solution back then that you may want to use: https://github.com/galkahana/HummusJSSamples/tree/lock-form/lock-form

galkahana avatar Jun 15 '18 15:06 galkahana

@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

tlrjs avatar Oct 05 '18 02:10 tlrjs

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) {
    ...
}

suniltandan avatar Mar 01 '19 10:03 suniltandan

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?

tylkomat avatar Jun 16 '19 15:06 tylkomat