The challenges of printing

I recently purchased a copy of Kim’s mouse macros which let you control the mouse with a voice commands. They come with a couple of Word documents which you can print out and then paste the coordinate guides to the edge of your screen. The problem for me was that the printed guides didn’t match my screen. So I figured I’d take a few minutes and write a small program to print my own mouse guides.

 

I’ve never used GDI+ before, but it didn’t take me much effort at all to printout some hash marks to the screen. And it was no effort on all to send the same image down to printer. The problem was that the printed image didn't match the screen image.

 

First I try changing the printers Graphic.PageUnit = GraphicsUnit.Pixel, but that made the printout really small. So then I tried scaling up the printout based on the ratio of the screen dpi to printer dpi, but that just resulted in the original printout.

So next I just experimented with scaling up by different percentages. 33% seem to work well. When I lined up the printout to the screen the hash marks on the left lined up but to the right they got out of alignment.

It took me a few seconds to realize that while the printout was flat, my monitor has a definite curve. I spent some time on Google searching for technical specs on my monitor, hoping to find some information on the curvature. The have proved futile, so then I tried to compensate for the curve by adding an additional scaling factor, this helped, but as it was a simple linear approach it wasn't good enough.

 

The next step, should I continue to pursue this, will be to get some plastic tubing, a tape measure, and find my old algebra and calculus textbooks.

 

2 Comments

  • The resolution issue is probably that your display resolution is setup wrong. Go to Control Panel -> Display -> Settings -> Advanced and pick Other... from Font Size and measure how long an inch actually is ;) Once you set that up properly your printouts will be exactly as you expect. But then - most Windows programmers assume that nobody has this right so they do things like you did, adjust with magic numbers.

  • If I remember correctly, there are some very good pointers for this in Charles Petzold's book Programming Windows with C#



    It is also an excellent book on many other aspects of GDI+ programming. Highly recommended.

Comments have been disabled for this content.