unipdf-examples
unipdf-examples copied to clipboard
PDF Form field too small for content
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)?


Thanks, Peter
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.
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
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