pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Flatten does not format multiline field correctly

Open alexbrickwedde opened this issue 5 years ago • 3 comments

Hi,

i have a template with a textfield, which is being filled. template.pdf

After being filled, this is the result: without flatten.pdf

After calling flatten, it looks like this: with flatten.pdf

I took a quick look into flatten, but i don't have enough experience with the internals of PDF.

alexbrickwedde avatar Aug 27 '21 11:08 alexbrickwedde

I think it's the same as #953

chislin avatar Aug 30 '21 14:08 chislin

I just tried with some more lines of text. It's just half a line added to the top position.

alexbrickwedde avatar Aug 30 '21 18:08 alexbrickwedde

Looks like the text field's line height is too large. pdf-lib should use whatever formatting is configured for a field when flattening it. You can decrease the line height in acrobat. I suspect that will fix this issue for you:

Large Line Height

Screen Shot 2021-09-24 at 6 32 45 PM

Small Line Height

Screen Shot 2021-09-24 at 6 32 53 PM

In theory pdf-lib could override the configured formatting if it detects that doing so would allow the text to fit within the field's bounds. But I'm not sure how widely used such a capability would be. If anybody is interested in working on this, I'm happy to accept PRs!

Hopding avatar Sep 24 '21 23:09 Hopding