unipdf-examples icon indicating copy to clipboard operation
unipdf-examples copied to clipboard

PDF Form field too small for content

Open whizkid79 opened this issue 2 years ago • 3 comments

Hi, We have an issue at the moment where we have a pdf template with form fields we use to customize the pdf with our data and print it. The results are great. But sometimes the text we want to put in, is too much for the size of the form field and gets cut off. We tried to increate the size of the field and make it multiline, which works for the longer text, but fails for shorter text because we cannot set it to be aligned to the bottom and that makes the shorter text float in mid air, not where it's supposed to. I added some screenshots for clarification.

Is there a good way to deal with this (programmatically)?

good case bad case

Thanks, Peter

whizkid79 avatar Jan 26 '23 11:01 whizkid79

Hi @whizkid79,

Could you share a runnable code snippet and pdf form file for this?

Have you tried to do something like

if len(firstName) > 30 {
  // do set the fields for first name to multiline
}

Like checking the field value and if exceeds maximum chars, set the field to multiline.

sampila avatar Jan 26 '23 12:01 sampila

Hi @sampila, sorry for the late reply. I haven't tried to check the string length. The issue is that 30x i is smaller than 30x X, so exact numbers won't work in all cases. Is there a way to detect the overflow? Or simply set the style of the formfield to vertical align on bottom? All fields get flattened, so it might also be done in the flattening operation later.

Thanks, Peter

whizkid79 avatar Feb 15 '23 09:02 whizkid79

Hi @sampila, another idea: is it possible to get the bounding box of a text element? I could do a test with the same font on a separate document and measure the used space for it, then check the width of the form field and adjust accordingly. Do you have any information on this approach? Thanks, Peter

whizkid79 avatar Mar 31 '23 08:03 whizkid79