I’ve put together a little demo to show you how to obtain the DPI of the printer that you are currently printing to in windows.
https://www.dropbox.com/s/tiod5twkggb9t0x/PrinterDPI.xojo_binary_project?dl=1
Notes:
-
Some printer drivers don’t return DPI for certain axis so you’ll need to best use what you are given.
-
dmCopies isn’t being set inside the DEVMODE structure (there may be other things but I’ve not really looked), but you can read that from Graphics.Copies anyway so not a deal breaker.
-
There is currently a bug (<https://xojo.com/issue/51489>) where by if you open a PrinterSetup.PageSetupDialog and pass the results of that to the OpenPrinterDialog the information inside the DEVMODE structure won’t be updated so you will only see the information for the default printer, NOT the selected printer that you are printing to (if that is different from default), hopefully Xojo will fix that for the next release.
However, if you call OpenPrinterDialog with a brand new uninitialised PrinterSetup as I have in the demo then it will work because it seems there’s another bug (?) where by if you send an uninitialised PrinterSetup to OpenPrinterDialog then 0,0 is in the top left corner of the paper which makes it super easy for placing things exactly where you want on the page. PrinterSetup.PageLeft and PrinterSetup.PageTop will show your left and top margins respectively so you can calculate where you can print as these will be set to the minimum margins for the printer. However, there is another bug (?) that is placing things ever so slightly up and right on the page, this is probably a rounding issue but it seems to be uniform across prints.
To get around this you will need to provide a method to your users to tweak the vertical and horizontal offset a bit if you want to hit calculated positions on pre-printed forms. I’ve not checked if this is a scaling issue so the discrepancy might alter across the print.
Let me know how you get on with the demo, if you want, print off a couple of test pages and measure the dots as accurately as you can and let me know if they are slightly off.
I can get it perfectly positioned in MS Word with every print and double checked with my digital calipers so its not my printer or printer driver that is causing the drift, I’ll post a feedback about it when I get a moment to collect my thoughts on it.