|
-
June 10th, 2005, 08:44 PM
#1
Printing out text to the printer?
I want to print out some text to the printer DC, but when reviewing the page
in PrintPreview, it's in the wrong place. The text is too far down.
I want my text to be roughly 0.5 inches high. I'm assuming 1 inch = 72 points,
so 0.5 inches = 36 points, in MM_TEXT mapping mode.
Code:
INT point_size = 36;
// I create some text using this formula, found in the SDK docs:
LOGFONT lf;
memset( &lf, 0, sizeof(LOGFONT));
// The value 72 is dependent on the mapping mode, MM_TEXT
INT fh = -MulDiv( point_size, pDC->GetDeviceCaps(LOGPIXELSY), 72 );
lf.lfHeight = fh;
// other variables set to default values
CFont myfont;
myfont.CreateFontIndirect(&lf);
// And then draw the text at location (0.5, 10) in inches:
INT ppi_x = pDC->GetDeviceCaps(LOGPIXELSX);
INT ppi_y = pDC->GetDeviceCaps(LOGPIXELSY);
INT x = (INT)(ppi_x * 0.5f);
INT y = (INT)(ppi_y * 10.0f);
// draw it directly to the printer DC
pDC->TextOut( x,y, "Test" );
But in PrintPreview, the text is too far down, past (0.5, 10) inches.
The map mode of the printer DC is set to MM_TEXT.
(LOGPIXELSX,LOGPIXELSY) for the printer DC returns (300,300).
(HORZRES,VERTRES) for the printer DC returns (2400,3074) as I selected
a (8.5 x 11 inch) paper size.
Question is, what is the correct way to print out text to the printer
at a specific location in inches?
Why isn't the text starting exactly at location (0.5, 10) inches?
-
June 10th, 2005, 09:07 PM
#2
Re: Printing out text to the printer?
Are you taking into account the physical margin imposed by the printer? Just a thought.
"trampling out the vintage"
-
June 10th, 2005, 09:14 PM
#3
Re: Printing out text to the printer?
Nope, I don't do anything else special to print out text. Why would that be
important when trying to print out text to a specific location?
The strange thing that I noticed is that:
(LOGPIXELSX,LOGPIXELSY) for the printer DC returns (300, 300).
(HORZRES,VERTRES) for the printer DC returns (2400, 3074).
Paper size selected: 8.5 x 11 inch.
Now, if I divide 2400/8.5, 3074/11 = (282,279)
Shouldn't this come out to (300,300) ?
-
June 10th, 2005, 09:25 PM
#4
Re: Printing out text to the printer?
[quote]
Paper size selected: 8.5 x 11 inch.
Now, if I divide 2400/8.5, 3074/11 = (282,279)
Shouldn't this come out to (300,300) ?
[/qoute]
No, there is .5 inches of margins horizontally, 2400/8 = 300, so .25 on each side, and the vertical printable area is about 10.25. 3074/10.25 = 299.9
-
June 10th, 2005, 09:26 PM
#5
Re: Printing out text to the printer?
That's strange. Instead of using values directly from GetDeviceCaps ,(300,300),
I used mine own calculated values above (282,279), and the text was drawn in the
correct spot!? What's going on? What are these physical margins and how do I query them?
-
June 10th, 2005, 09:41 PM
#6
Re: Printing out text to the printer?
Cool, I think I just found my answer:
// HOWTO: How to Use a Program to Calculate Print Margins
http://support.microsoft.com/default...b;en-us;122037
-
June 11th, 2005, 12:58 AM
#7
Re: Printing out text to the printer?
I think I figured out what's happening. The printer DC in PrintPreview only gives me
access to the printable area, which is only 8 x 10.25, and I'm trying to stretch my
entire 8.5 x 11 page into that. I hope that sounds correct.
I assumed I had complete access to the full 8.5x11 page area, printable and nonprintable,
but apparently, that's not the case.
-
June 11th, 2005, 08:30 AM
#8
Re: Printing out text to the printer?
With that being said, is there a way to programmically force the printer DC to give
me access to the full 8.5x11 page area, printable and nonprintable?
Is it possible to programmically zero out the internal printer margins?
-
June 11th, 2005, 02:54 PM
#9
Re: Printing out text to the printer?
I'm not sure if this is even possible. Some docs say printers store their 'private' data immediately
after the DEVMODE structure (internal margin data, etc..), which doesn't have to follow any kind of
format, so a program won't know how to read it, well, at least it won't be consistent from printer
to printer.
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
|