galkahana / HummusJS

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

Error while trying to fill form fields: Inconsistent ending of dictionary. Wrong nesting of startDictionary and endDictionary #303

Open gomikestrat opened 6 years ago

gomikestrat commented 6 years ago

Hello,

I've followed the form fill example ( http://pdfhummus.com/post/161128437261/a-good-day-to-everyone-today-we-will-discuss-a ) and I have come across this error:

Inconsistent ending of dictionary. Wrong nesting of startDictionary and endDictionary TypeError: Inconsistent ending of dictionary. Wrong nesting of startDictionary and endDictionary

Log file:

ObjectsContext::EndDictionary, stack underflow. Trying to end a dictionary when there's no open dictionaries

With the pdfs provided on the example I can successfully fill the forms but some other pdfs (v1.6) that I've got produce this error. Does it have to do with the supplied pdf? I can always read all the form fields successfully.

Ventajou commented 6 years ago

I'm encountering the same error, it happens whenever I create a text field with 2 child widgets. In my case, I've tracked it down to the following lines: https://github.com/galkahana/HummusJSSamples/blob/master/filling-form-values/pdf-form-fill.js#L195-L197

When I comment them out, the error disappears but the resulting PDF is invalid. I've not been able to figure out what was wrong.

Ventajou commented 6 years ago

@gomikestrat take a look at https://github.com/galkahana/HummusJSSamples/pull/20 and see it if fixes the issue for you

gomikestrat commented 6 years ago

@Ventajou yes my friend, your fix works! Excellent work! There is a minor issue though: the text is not aligned correctly in the field and its cropped a little bit but I'll mess a bit with the code and I'll figure something out.

hnitzsche commented 6 years ago

@gomikestrat look for xobjectForm.getContentContext() inside the writeAppearanceXObjectForText() function and chain in .Tm(1,0,0,1,0,3) for example. Adjust the bold value to your needs then.

pgrmCreate commented 5 years ago

I got the same error on "NodeJs" and "log file" and when i try this pdf-form-fill.js on this pull request, i have on ouput a simple copy of my pdf in input.

It is solved with version 101 of hummus ?