Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Determine how many lines will fit inside of a form field

Question

I am filling a form field with text that overflows the field's visible area. I'd like to fill in just the text that will be visible, and determine what the overflow text is.

Thus far I've been able to do this to, I think, get the individual lines of broken text based on the width of the field:

double fieldWith = qp.GetFormFieldBound(index, 3);
overflowText = qp.GetWrappedText(fieldWith, @"#LINEBREAKHERE# ", 
valueToSetFieldTo);
string[] lineSeparator = new string[] { "#LINEBREAKHERE#" };
List<string> textLines = overflowText.Split(lineSeparator, 
StringSplitOptions.RemoveEmptyEntries).ToList();

Now, how do I determine how many of those lines will fit into the form field? In Acrobat I set the field to use 10 pt Helvetica, multi-line.

Answer

The GetWrappedText function returns the positions based on the current font.

You would also need to get the field height.

double fieldHeight = qp.GetFormFieldBound(index, 4);

If you measurement system is using the default points setting (QP.SetMeasurementUnits(0) then this should give a pretty good estimate.

lines = (fieldheight - borders) / pointsize;  // it there are borders.

There may be some borders added to the form field that you may have to allow for.

The point size of a font is also the distance between the baselines of two lines of text when printing that font with normal linespacing.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum