Results 1 to 11 of 11

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    5

    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

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,238

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

    Every reference i found had to do with the SetTextAlign-Function
    One System to rule them all, One IDE to find them,
    One Code 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.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    5

    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.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,238

    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
    One System to rule them all, One IDE to find them,
    One Code 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.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    5

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

    Quote Originally Posted by Zvoni View Post
    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.

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,238

    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"
    One System to rule them all, One IDE to find them,
    One Code 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.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  7. #7
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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) ?

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    5

    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!

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,238

    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
    One System to rule them all, One IDE to find them,
    One Code 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.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    5

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

    Same size (A4). But thanks for not giving up!

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

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

    Quote Originally Posted by stefanP View Post
    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
  •  



Click Here to Expand Forum to Full Width