string fill_field_by_chars(AcroFields form, string field_key, string text) { IList <AcroFields.FieldPosition> p = form.GetFieldPositions(field_key); float width = p[0].position.Width; text = FieldPreparation.Prepare(text); int end = 0; for (int e = 1; e <= text.Length; e++) { float w = baseFont.GetWidthPoint(text.Substring(0, e).Trim(), (float)fontSize); if (w > width) { break; } end = e; } set_field(form, field_key, text.Substring(0, end).Trim()); return(text.Substring(end)); }
string fill_field_by_words(AcroFields form, string field_key, string text) { IList <AcroFields.FieldPosition> p = form.GetFieldPositions(field_key); float width = p[0].position.Width; text = FieldPreparation.Prepare(text); int end = 0; for (Match m = Regex.Match(text, @".+?([\-\,\:\.]+|(?=\s)|$)"); m.Success; m = m.NextMatch()) { int e = m.Index + m.Length; float w = baseFont.GetWidthPoint(text.Substring(0, e).Trim(), (float)fontSize); if (w > width) { break; } end = e; } set_field(form, field_key, text.Substring(0, end).Trim()); return(text.Substring(end)); }