Set Print Page height programmatically?

  • Thread starter Thread starter Duong Nguyen
  • Start date Start date
D

Duong Nguyen

Hello,
I am trying to program to work with POS-Printer in page mode. So I want to
set the page height at run time. Depend on the number of lines to draw to
Canvas, I must set the Page height.
So I can get the height in pixel Height = LineCount *
font.GetHeight(GraphicsObject);
and set the page size:
prndoc.DefaultPageSettings.PaperSize = new
System.Drawing.Printing.PaperSize("custom", width, height);

width and height is in Hundredth of an inch.

So How can I convert from Height (in Pixel) to Height in hundredth of an
inch?
 
Duong,

To calculate the size in pixels you need to have information regarding
pronter's DPI (resolution).

Here is an example how this can be calculated:

PrinterSettings ps = new PrinterSettings();
Graphics g = ps.CreateMeasurementGraphics();
MessageBox.Show(g.DpiX.ToString() + ", " + g.DpiY.ToString());

double width = 100 * widthInPixels / g.DpiX;
double height = 100 * heightInPixels / g.DpiY;
 
Back
Top