How to define the space a string will occupy in C# / Pdfsharp

Asked

Viewed 224 times

1

I would like to define how far the string will take up space. the values (200,50) refer to the beginning of the text x= 200 y =50, the other 2 values I do not know for what it serves, even doing some tests.

textFormatter.DrawString("texto texto texto texto", fontTitulo,
PdfSharp.Drawing.XBrushes.Black,
new PdfSharp.Drawing.XRect(200,50, 10, 50));
  • usually, these values are X, Y, W, H... the last two, width and height. In the case, rectangle, not text

  • @Rovannlinhalis this, I see the folks using this "(200,50,page.Height, page.Width)" so I believe this is really is the limit, but by changing the value it does not alter.

1 answer

0


As we can see in pdfsharp code, the constructor is defined as: public XRect(double x, double y, double width, double height).

Thinking of the two axes, X (Horizontal from left to right) and Y (Vertical from top to bottom) we have a point X,Y that is the starting point of the rectangle.

Then we have the value W (Width / Width) and H (Height / Height) which are respectively the width and height of the rectangle.

Example:

Exemplo Rectangle

From what I could see again in pdfsharp code, this parameter is only used to calculate position and alignment of the text.

And for you to know the size that the string will occupy, you use the method MeasureString that you inform the text, and the source and is returned an object XSize with the width and height of the text.

  • Thanks for your help, I’ve thought about using the Measurestring method, however I can’t "split" the word out of the English patterns, I was thinking about defining a space to add text, but really it just defines position and alignment of the text ):

  • Right, in this answer I show how to resize the text to fit on the screen if it is interesting: https://answall.com/a/254130/69359 Anyway, if it helped you do not forget to mark as answer. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.