I have got an issue with
e.Graphics.DrawString(TextToPrint, Font, Brush, New RectangleF(StartPositionX, StartPositionY, Width, Height))
Let's say I want to print "Hello World" in Arial-20pt at 25mm on the x-axis from the left edge. In addition, I use a version with Arial-50pt.
For that I set
e.Graphics.PageUnit = GraphicsUnit.Millimeter
and
PrintDocument.OriginAtMargins = False
I print a PDF via "PDFCreator" and use the measuring tool of Acrobat Reader.
The position on the y-axis is as desired. Check!
The "H" starts at about 26.6mm (Arial-20pt) / 29.3mm (Arial-50pt).
So I also print a rectangle at the same starting points with
e.Graphics.FillRectangle
and fill it green.
This rectangle starts at 25mm!!
So I assume that there is a sort of margin around the text. On the y-axis it is possible to find the lowest point of the "H" with the help of "CellAscent".
Is there a value/function for the x-axis?
Here is my code:
e.Graphics.PageUnit = GraphicsUnit.Millimeter
PrintDocument.OriginAtMargins = False
TextToPrint = "Hello World"
Font = New Font("Arial", 20)
Brush = Brushes.Black
StartPositionX = 25
StartPositionY = 30
Width = 50
Height = 60
I want to use the exact position of the first left-bottom pixel of the "H" as my starting point. For the y-axis this works:
CellAscent = Font.Size * CSng(Font.FontFamily.GetCellAscent(Font.Style)/ Font.FontFamily.GetEmHeight(Font.Style))
StartPositionY = StartPositionY - CellAscent
After this adjustments I use
e.Graphics.DrawString(TextToPrint, Font, Brush, New RectangleF(StartPositionX, StartPositionY, .Width, .Height))