I'm using iTextSharp to populate some PDFs containing forms. These forms consist of textboxes (among other field types) and if I open them in a PDF reader, I can type in arbitrary number of characters without any limitations. But if I print such a PDF form while I entered too many characters in a field, the overflow won't be printed at all.
Now I'm looking for a way to measure the maximum length of a string that fits in some specific textbox without losing any printed data. I know what I need to do in theory, I need to measure the width of the string (in pixels/points) considering the font properties of the textbox and then compare it with the width of the textbox (minus any padding it might have). But I'm all new to PDF concepts and I don't know where to start. Could someone please guide me to the right direction?
One more thing, I've got no control over the template PDFs and I can not change them in any way. All I can do is to prompt the user that your entered text won't fit in the field when he asks for a flattened PDF file!
[UPDATE]
There's another scenario which I was hoping the same solution would apply to, but it seems I need to include this later one as well to guide the answers to the right direction.
I've got three textboxes in my PDF form file and when I'm filling them manually (using a PDF reader), it's my responsibility to split my input among three of them. An example of this is three lines of an address field. If I was designing the form, I would use a multi-line text field so the address wraps automatically but unfortunately I'm just handed the forms and since they are password protected, all I can do is to find the appropriate point to split the input string to enter them in three fields.