Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

TextOut: printed text displaced on paper, correct when printing to PDF

$
0
0
Hi! I am printing some text using the API function TextOut. The following code snippet shows how I am converting my coordinates to pixels:

'The TextOut function expects the x and y coordinates in pixels
CurrentX = CurrentX / Printer.ScaleWidth * Printer.width / Printer.TwipsPerPixelX
CurrentY = CurrentY / Printer.ScaleHeight * Printer.Height / Printer.TwipsPerPixelY

hfontOld = SelectObject(hdc, hfont) 'No reference to Printer object beyond this line!

TextOut hdc, CurrentX, CurrentY, Txt, Len(Txt) 'Printer.print cannot be used with API-defined fonts


Now when I select "PDF Creator" in the printer dialog, the printing results are as expected, but when I use a real printer, the text gets displaced. The larger CurrentX or CurrentY, the larger the displacement, so there seems to be a wrong factor (about 2.5% off). A friend of mine tested my code on his computer with his printer - same result!

I have no explanation why real printers and PDF printers behave differently!

VB6, Win 7

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>