-
Feb 24th, 2015, 04:26 PM
#1
Thread Starter
New Member
TextOut: printed text displaced on paper, correct when printing to PDF
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
-
Feb 25th, 2015, 05:38 AM
#2
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Every reference i found had to do with the SetTextAlign-Function
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 25th, 2015, 06:08 AM
#3
Thread Starter
New Member
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Thank you Zvoni. Unfortunately in my case the displacement is not constant. It is proportional to the distance from the upper left corner, so the factor is wrong somehow.
-
Feb 25th, 2015, 06:26 AM
#4
Re: TextOut: printed text displaced on paper, correct when printing to PDF
OK.
let's do it this way:
Debug your code and read all values before printing.
CurrentX, CurrentY, Printer.ScaleWidth etc. and everything else.
Read them for your PDF-Printer, and then read them for the "real" printer.
Maybe some clues are hidden in there
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 25th, 2015, 09:54 AM
#5
Thread Starter
New Member
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Originally Posted by Zvoni
Debug your code and read all values before printing.
CurrentX, CurrentY, Printer.ScaleWidth etc. and everything else.
Read them for your PDF-Printer, and then read them for the "real" printer.
Maybe some clues are hidden in there
Actually that's what I did before I decided to post in this forum. I compared all relevant properties - no difference! At least no significant difference that would explain the effect.
-
Feb 26th, 2015, 06:22 AM
#6
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Then the only explanation i'd have is, that the "real" printer displaces the position due to border-issues (which logically a PDF-Printer shouldn't have)
since CurrentX and CurrentY are logical coordinates.
Maybe the real printer needs some 0.5 inches of border, and the position doesn't start at top left (0,0) but at somewhere more "inside"
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 26th, 2015, 11:01 AM
#7
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Perhaps your printer device context is not set to use the MM_TEXT map mode (See GetMapMode) ?
-
Feb 26th, 2015, 05:20 PM
#8
Thread Starter
New Member
Re: TextOut: printed text displaced on paper, correct when printing to PDF
@Zvoni: Wouldn't that lead to a constant displacement? Anyway, in the printer properties dialog I tried to set the printing borders to zero. No change.
@Merrion: It is set to MM_TEXT, unfortunately. Nice idea though!
-
Feb 27th, 2015, 06:20 AM
#9
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Just a thought: The PDF and the real printer use the same paper-"size"?
e.g. PDF is set to A4, while the real printer is set to letter
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 27th, 2015, 06:25 AM
#10
Thread Starter
New Member
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Same size (A4). But thanks for not giving up!
-
Mar 7th, 2015, 10:38 PM
#11
Re: TextOut: printed text displaced on paper, correct when printing to PDF
Originally Posted by stefanP
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
Your above x,y calculation looks - well - "adventurous"...
Seeing you work with GDI-Functions - may I ask, why you didn't switch the Printer into vbPixels-Scalemode?
(then giving the Coords to your GDI-Functions directly as Pixels - without any conversion needed).
Also take into account - that on "physical" printers, the value of Printer.ScaleLeft needs to be considered.
On PDF-Printers (which have no physical restriction with regards to their Printable-Area) this value is usually Zero -
whilst on physical Printers it is almost always larger than Zero.
Olaf
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|