title: Calculating the maximum string length that fits in a PDF's form textbox using iText
body: <p>I'm using <strong>iTextSharp</strong> to populate some <strong>PDF</strong>s 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.</p>
  
  <p>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?</p>
  
  <p>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!</p>
  
  <p><strong>[UPDATE]</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>