I have a requirement to measure the text length in a PDF and wrap the line if the length exceeds a certain amount. I am already using PDFsharp library.
I already used the following code to determine the length of the text.
public static Size MeasureString(string s, Font font)
{
SizeF result;
using (var image = new Bitmap(1, 1))
{
using (var g = Graphics.FromImage(image))
{
result = g.MeasureString(s, font);
}
}
return result.ToSize();
}
As I understood I am pretty dependent of the resolution and dpi to convert Height
and Width
properties of the Size
class to millimeter. But according to the PDFsharp's team answer in this post "PDF files are vector files that have no DPI".
So I am a bit confused about the right way to measure the text length using this library.