Calculating size of PdfFreeTextAnnotation from String width.

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Calculating size of PdfFreeTextAnnotation from String width.

Post by IntegraHarlan »

Hi,
I am trying to calculate the size of a PdfFreeTextAnnotation based on a maximum width.
I am using the MeasureString method. This seams to work fine unless I want to wrap the text.
If I have a text string that is 1000 pixels wide, but my PdfFreeTextAnnotation is only 50 pixels wide, I would like to size the height of the annotation to fit the text with the maxWidth of the annotation being 50.

I tried to use this method of the PdfGraphics class.

Code: Select all

public void MeasureString( 
   string text,
   PdfFont font,
   float fontSize,
   float maxWidth,
   bool wordWrap,
   out float width,
   out float height
)
I would expect to set the maxWidth value to 50 and have the out width value be 50 with the out height value set to a height to fit the wrapped text.
However, the width value seems to default to 100 and I get a height value that seems almost arbitrary. It is generally much taller than it needs to be to fit the text for the width of 100 and to short for a width of 50.
I am using the Winforms version of the Pdf.Net plugin.

Any help would be appreciated.

Thanks
Harlan.
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Calculating size of PdfFreeTextAnnotation from String width.

Post by Alex »

Hi Harlan,

Please send us (to support@vintasoft.com) a small project, which demonstrates your problem. We need to reproduce the problem on our side.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Calculating size of PdfFreeTextAnnotation from String width.

Post by IntegraHarlan »

Hi Alex,
I have submitted code to reproduce my problem to your support email.

Thanks
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Calculating size of PdfFreeTextAnnotation from String width.

Post by Alex »

Hi Harlan,

We created the PdfFreeTextExpansionController class, which allows to control behaviour of PDF free text annotation, and send it to you. Please use the class and let me know if you will have any question or problem. Class can be used with version 9.1.0.3 or higher.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Calculating size of PdfFreeTextAnnotation from String width.

Post by IntegraHarlan »

Thank you Alexander, I will give it a try.
Post Reply