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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top