Problem Printing

This is a discussion on Problem Printing within the Windows Programming forums, part of the Platform Specific Boards category; I cannot figure out why this is happening and it's driving me mad. Please assist if at all possible. I ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Question Problem Printing

    I cannot figure out why this is happening and it's driving me mad. Please assist if at all possible.

    I am writing a class to simplify text printing. The entire class is basically finished, but the one problem is that the last 3 characters on each line (if they reach to the end of the line) are not there!

    I've tried the code in simplest terms to try to find the problem but to no avail. I'm doing a simple CDC::TextOut() of a line that fits on the page. In fact, it goes all the way right up to the right border, but, again, the last three characters are "invisible."

    The CDC::GetTextExtent() of the string I'm printing is 4800 and the width of a page is 4800. The rect dimensions of the page are left=0, right=4800, top=50, bottom=6350 (with a 1/4" margin all around).

    I don't want to just limit the length of a line to 3 characters less because the page will look crooked as one side with have the correct margin and the other will be larger. And besides that with a different font (I'm using courier new currently) it may be more or less than 3 characters.

    Do you have any idea why this is happening??? Please help. Thanks much in advance.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    This is just a guess. But how are you calculating the number of pixels to 1/4 inch horizontally? I believe the x & y dpi values for printers are not necessarily the same. I.e.

    GetDeviceCaps(PrinterHandle, LOGPIXELSY);

    and

    GetDeviceCaps(PrinterHandle, LOGPIXELSX);

    may yield slightly different values.

    Could this be the source of your problem?

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Unfortunately, no, that is not the problem. Since the device's printable region as calculated by the GetDeviceCaps() values is not consistent between printers, I have calculated the margin by retrieving the actual device units in twips mode then converting them to logical units.

    Any other ideas?

    Do any of you have a program where you print text across the entire horizontal span of the page where all characters are visible?

    *scratching my head*

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    I do. But unfortunately this is written in C++ Builder speak. I rarely use Win API calls directly.

    In this, I add a margin around the page, but specify the margin in terms of a configurable percentage page height/width (i.e. around 5%). It seems to work even if margins are set to zero. However, the Borland component library are encapsulating a lot of what you may be doing. So I'm not sure how much help this would be.
    Last edited by Davros; 01-20-2003 at 11:44 AM.

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Like you, I rarely use win API. I base most all of my windows programming on MFC, but that's neither here nor there.

    I'm beginning to think that I should do little more than ignore the problem... I just printed the exact same line that I printed from my program with notepad with .25" all around again. While the margins seem to be padded a little bit by notepad, it too has disappeared a character at the end of the line (just one as opposed to my three).
    I also printed the same data with a .50" margin and nothing was missing... Although I don't know the source of the problem, I know that microsoft did the same as I propose (to ignore it), so I guess it's okay to do the same... ?
    Or perhaps I'll do what it appears notepad does and just add an extra buffer in addition to the margins. That sound like a disgusting idea or you think I should make like nike and just do it?

  6. #6
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    This is another wild guess.

    Do you have such a concept as a clip rectangle with your printer canvas? With Borland VCL, library objects & methods usually just encapsulate Win API functionality. So I'm guessing you might have.

    If this is so, is there a default margin setting in your printer driver configuration window? If so this may set the printer canvas clip rectangle to be inside the physical dimensions of the page. Any region printed outside this rectange will not be rendered, even if it were physical within the page area.

    If this sounds familiar, are you checking to ensure that your CDC::GetTextExtent() calls take into account this clip rect, rather than just the raw page rect?
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  7. #7
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    As far as my code is concerned there is no clipping happening at all. I had given this a thought too; like that perhaps there is some magical rect that I am supposed to restrict my writes to.

    I am quite positive now that it's just the way it goes. I printed the same line again with .25" margins, but this time from MS Word. The same thing happened from word as from my program. Exact same margin width and character size/spacing and at the end of the line, guess what. There were characters missing! So apparently it has nothing to do with my code (thank goodness since it is very straight forward).
    It does, however, just seem to be a problem with 1/4" margins (or smaller I'd presume), and who knows, it may be a problem with the printer too (HPLaserJet8150).

    Thanks for all your assistance Davros.

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Sounds like your printer can't handle margins that small.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Problem Printing to File
    By jamez05 in forum C++ Programming
    Replies: 10
    Last Post: 09-26-2006, 11:20 AM
  3. Replies: 1
    Last Post: 06-07-2006, 09:42 AM
  4. Message printing problem
    By robert_sun in forum C Programming
    Replies: 1
    Last Post: 05-18-2004, 05:05 AM
  5. problem with printing a structed array using for loop
    By Prezo in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2002, 09:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21