Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
7k stars 676 forks source link

Should not throw an error when setting text value to a form field with MaxLen = 0 #1554

Open blikblum opened 12 months ago

blikblum commented 12 months ago

What were you trying to do?

Set text of field with MaxLen = 0

How did you attempt to do it?

Use setText method of a TextField with MaxLen = 0

field.setText('XXX')

What actually happened?

An error is throw :

Uncaught (in promise) Error: Attempted to set text with length=3 for TextField with maxLength=0 and name=patient.name

What did you expect to happen?

The field text should be set without errors. This is the behavior of PDF Viewers like Adobe Reader, Foxit, Evince

How can we reproduce the issue?

Below is a pdf file with two fields. The first with MaxLen = 0. The second with MaxLen = 10

The first one is possible to add values with size restriction. The second one is limited to 10 characters

test-max-len.pdf

Version

1.17

What environment are you running pdf-lib in?

Browser

Checklist

Additional Notes

No response

vipulparmarmt commented 12 months ago

Can you able to save the edited Pdf on local device which edited by user ? @blikblum

blikblum commented 12 months ago

Can you able to save the edited Pdf on local device which edited by user ? @blikblum

Yes. Here is the above file saved with Adobe Reader test-max-len-saved.pdf