Hello!
I'm trying to measure height of some text for table printing purpose.
Here's the code. In my case it prints different numbers in preview and on actual page. I can't try on any printers other than Microsoft Office Document Image Writer right now, but I'm pretty sure it isn't a printer issue.
Perhaps somebody have found a workaround for this problem?
private void button1_Click(object sender, EventArgs e)
{
Print();
}
public void Print()
{
PrintDocument my_doc = new PrintDocument();
my_doc.PrintPage += new PrintPageEventHandler(this.PrintPage);
PrintPreviewDialog my_preview = new PrintPreviewDialog();
my_preview.Document = my_doc;
my_preview.ShowDialog();
my_doc.Dispose();
my_preview.Dispose();
}
private void PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Pixel;
string s = "String height is ";
SizeF h = e.Graphics.MeasureString(s, new Font("Arial", 24));
e.Graphics.DrawString(s + Convert.ToString(h.Height),
new Font("Arial", 24), new SolidBrush(Color.Black), 1, 1);
}