By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Print Preview=GOOD, Printout=BAD

P: n/a
Print Preview looks perfect, but the Printout is cut off (extends off
the page).

Has anyone else experienced this? A3 paper size seems to exacerbate the
problem.

I can't believe it because the same code is executed with the same exact
values when Printing and doing Print Preview.

I've seen something like this in old Win32 programming caused by bad
Printer Drivers, but that does not seem to be the case here.
Devin Dow
Router Solutions Incorporated
De*******@rsi-inc.com
Oct 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Devin,
My guess would be that you are seeing the effect of the printer's 'hard
margins'. Using FW 1.x the origin of the print area for print preview is
0,0 of the bitmap but for the printer it is x,y where x and y are the
printer's hard margins respectively. You can search for GetHardMargins in
this ng to see some code to get around this. This is basically PInvoke on
GetDeviceCaps to get the margins followed by a TranslateTransform on the
Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBounds for the Graphics and do the transform if the Height/Width
of this is less than the page size.

If you can't find the actual code reply here and I'll post it again
(C#). If you are using VB.Net look in microsoft.public.dotnet.languages.vb
for a translation.

Ron Allen

"Devin Dow" <De*******@rsi-inc.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Print Preview looks perfect, but the Printout is cut off (extends off the
page).

Has anyone else experienced this? A3 paper size seems to exacerbate the
problem.

I can't believe it because the same code is executed with the same exact
values when Printing and doing Print Preview.

I've seen something like this in old Win32 programming caused by bad
Printer Drivers, but that does not seem to be the case here.
Devin Dow
Router Solutions Incorporated
De*******@rsi-inc.com

Oct 17 '05 #2

P: n/a
Ron,

If you don't mind, will you go ahead and post your code. I think I
might be needing to do something similar in the next few weeks and it
may save me some time. Thanks a lot.

Jason Newell
Ron Allen wrote:
Devin,
My guess would be that you are seeing the effect of the printer's 'hard
margins'. Using FW 1.x the origin of the print area for print preview is
0,0 of the bitmap but for the printer it is x,y where x and y are the
printer's hard margins respectively. You can search for GetHardMargins in
this ng to see some code to get around this. This is basically PInvoke on
GetDeviceCaps to get the margins followed by a TranslateTransform on the
Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBounds for the Graphics and do the transform if the Height/Width
of this is less than the page size.

If you can't find the actual code reply here and I'll post it again
(C#). If you are using VB.Net look in microsoft.public.dotnet.languages.vb
for a translation.

Ron Allen

"Devin Dow" <De*******@rsi-inc.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Print Preview looks perfect, but the Printout is cut off (extends off the
page).

Has anyone else experienced this? A3 paper size seems to exacerbate the
problem.

I can't believe it because the same code is executed with the same exact
values when Printing and doing Print Preview.

I've seen something like this in old Win32 programming caused by bad
Printer Drivers, but that does not seem to be the case here.
Devin Dow
Router Solutions Incorporated
De*******@rsi-inc.com


Oct 18 '05 #3

P: n/a
Jason,
Here is the code. Modify as desired. NOTE: I took out a lot of <summary>
blocks that make the constants compile without warnings. They just said the
same thing as the comments at the end.
====================snip=======================
namespace RLA.GetCaps
{
using System;
using System.Runtime.InteropServices;
/// <summary>
/// GetDeviceCaps and associated calls/values
/// </summary>
/// <remarks>
/// Use as desired. No warranties implied.
/// RLA 7/3/2002
/// </remarks>
public class GetDevCaps
{
#region "Device Parameters"
/* Device Parameters for GetDeviceCaps() */

public static short DRIVERVERSION = 0; // Device driver version
public static short TECHNOLOGY = 2; // Device classification
public static short HORZSIZE = 4; // Horizontal size in
millimeters
public static short VERTSIZE = 6; // Vertical size in millimeters
public static short HORZRES = 8; // Horizontal width in pixels
public static short VERTRES = 10; // Vertical height in pixels
public static short BITSPIXEL = 12; // Number of bits per pixel
public static short PLANES = 14; // Number of planes
public static short NUMBRUSHES = 16; // Number of brushes the device
has
public static short NUMPENS = 18; // Number of pens the device
has
public static short NUMMARKERS = 20; // Number of markers the device
has
public static short NUMFONTS = 22; // Number of fonts the device
has
public static short NUMCOLORS = 24; // Number of colors the device
supports
public static short PDEVICESIZE = 26; // Size required for device
descriptor
public static short CURVECAPS = 28; // Curve capibilities
public static short LINECAPS = 30; // Line capibilities
public static short POLYGONALCAPS = 32; // Polygonal capibilities
public static short TEXTCAPS = 34; // Text capibilities
public static short CLIPCAPS = 36; // Clipping capibilities
public static short RASTERCAPS = 38; // Bitblt capibilities
public static short ASPECTX = 40; // Length of the X leg
public static short ASPECTY = 42; // Length of the Y leg
public static short ASPECTXY = 44; // Length of the hypotenuse
public static short PHYSICALWIDTH = 110; // Physical Width in device
units
public static short PHYSICALHEIGHT = 111; // Physical Height in device
units
public static short PHYSICALOFFSETX = 112; // Physical Printable Area x
margin
public static short PHYSICALOFFSETY = 113; // Physical Printable Area y
margin
public static short SCALINGFACTORX = 114; // Scaling factor x
public static short SCALINGFACTORY = 115; // Scaling factor y
#endregion
public static float TwipsPerInch = 1440.0f;
public static float InchesPerTwip = 1.0f / TwipsPerInch;
public static float PointsPerInch = 72.0f;
public static float InchesPerPoint = 1.0f / PointsPerInch;

/// <summary>
/// Call the GetDeviceCaps Win32 method
/// </summary>
[DllImport("gdi32.dll")]
public static extern Int16 GetDeviceCaps(
[In] [MarshalAs (UnmanagedType.U4)] int hDc,
[In] [MarshalAs (UnmanagedType.U2)] Int16 funct);
/// <summary>
/// Return the device 'hard' margins for the passed in
/// Device Context handle. Return data in 1/100ths inch
/// </summary>
/// <param name="hDc">Input handle</param>
/// <param name="left">output left margin in 1/100ths inch</param>
/// <param name="top">output top margin in 1/100ths inch</param>
/// <param name="right">output right margin in 1/100ths inch</param>
/// <param name="bottom">output bottom margin in 1/100ths inch</param>
public static void GetHardMargins(int hDc, ref float left, ref float top,
ref float right, ref float bottom)
{
float offx = Convert.ToSingle(GetDeviceCaps(hDc, PHYSICALOFFSETX));
float offy = Convert.ToSingle(GetDeviceCaps(hDc, PHYSICALOFFSETY));;
float resx = Convert.ToSingle(GetDeviceCaps(hDc, HORZRES));
float resy = Convert.ToSingle(GetDeviceCaps(hDc, VERTRES));
float hsz = Convert.ToSingle(GetDeviceCaps(hDc, HORZSIZE))/25.4f; //
screen width in inches
float vsz = Convert.ToSingle(GetDeviceCaps(hDc, VERTSIZE))/25.4f; //
screen height in inches
float ppix = resx/hsz;
float ppiy = resy/vsz;
left = (offx/ppix) * 100.0f;
top = (offy/ppix) * 100.0f;
bottom = top + (vsz * 100.0f);
right = left + (hsz * 100.0f);
}
}
}
========================snip====================== ====
"Jason Newell" <no****@nospam.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Ron,

If you don't mind, will you go ahead and post your code. I think I might
be needing to do something similar in the next few weeks and it may save
me some time. Thanks a lot.

Jason Newell
Ron Allen wrote:
Devin,
My guess would be that you are seeing the effect of the printer's
'hard margins'. Using FW 1.x the origin of the print area for print
preview is 0,0 of the bitmap but for the printer it is x,y where x and y
are the printer's hard margins respectively. You can search for
GetHardMargins in this ng to see some code to get around this. This is
basically PInvoke on GetDeviceCaps to get the margins followed by a
TranslateTransform on the Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBounds for the Graphics and do the transform if the
Height/Width of this is less than the page size.

If you can't find the actual code reply here and I'll post it again
(C#). If you are using VB.Net look in
microsoft.public.dotnet.languages.vb for a translation.

Ron Allen

------------------snip==============
Oct 21 '05 #4

P: n/a
Ron,

Thank you very much. I saved your code and will evaluate it when I get
to the printing part of my application. Thanks again!

Jason Newell
Ron Allen wrote:
Jason,
Here is the code. Modify as desired. NOTE: I took out a lot of <summary>
blocks that make the constants compile without warnings. They just said the
same thing as the comments at the end.
====================snip=======================
namespace RLA.GetCaps
{
using System;
using System.Runtime.InteropServices;
/// <summary>
/// GetDeviceCaps and associated calls/values
/// </summary>
/// <remarks>
/// Use as desired. No warranties implied.
/// RLA 7/3/2002
/// </remarks>
public class GetDevCaps
{
#region "Device Parameters"
/* Device Parameters for GetDeviceCaps() */

public static short DRIVERVERSION = 0; // Device driver version
public static short TECHNOLOGY = 2; // Device classification
public static short HORZSIZE = 4; // Horizontal size in
millimeters
public static short VERTSIZE = 6; // Vertical size in millimeters
public static short HORZRES = 8; // Horizontal width in pixels
public static short VERTRES = 10; // Vertical height in pixels
public static short BITSPIXEL = 12; // Number of bits per pixel
public static short PLANES = 14; // Number of planes
public static short NUMBRUSHES = 16; // Number of brushes the device
has
public static short NUMPENS = 18; // Number of pens the device
has
public static short NUMMARKERS = 20; // Number of markers the device
has
public static short NUMFONTS = 22; // Number of fonts the device
has
public static short NUMCOLORS = 24; // Number of colors the device
supports
public static short PDEVICESIZE = 26; // Size required for device
descriptor
public static short CURVECAPS = 28; // Curve capibilities
public static short LINECAPS = 30; // Line capibilities
public static short POLYGONALCAPS = 32; // Polygonal capibilities
public static short TEXTCAPS = 34; // Text capibilities
public static short CLIPCAPS = 36; // Clipping capibilities
public static short RASTERCAPS = 38; // Bitblt capibilities
public static short ASPECTX = 40; // Length of the X leg
public static short ASPECTY = 42; // Length of the Y leg
public static short ASPECTXY = 44; // Length of the hypotenuse
public static short PHYSICALWIDTH = 110; // Physical Width in device
units
public static short PHYSICALHEIGHT = 111; // Physical Height in device
units
public static short PHYSICALOFFSETX = 112; // Physical Printable Area x
margin
public static short PHYSICALOFFSETY = 113; // Physical Printable Area y
margin
public static short SCALINGFACTORX = 114; // Scaling factor x
public static short SCALINGFACTORY = 115; // Scaling factor y
#endregion
public static float TwipsPerInch = 1440.0f;
public static float InchesPerTwip = 1.0f / TwipsPerInch;
public static float PointsPerInch = 72.0f;
public static float InchesPerPoint = 1.0f / PointsPerInch;

/// <summary>
/// Call the GetDeviceCaps Win32 method
/// </summary>
[DllImport("gdi32.dll")]
public static extern Int16 GetDeviceCaps(
[In] [MarshalAs (UnmanagedType.U4)] int hDc,
[In] [MarshalAs (UnmanagedType.U2)] Int16 funct);
/// <summary>
/// Return the device 'hard' margins for the passed in
/// Device Context handle. Return data in 1/100ths inch
/// </summary>
/// <param name="hDc">Input handle</param>
/// <param name="left">output left margin in 1/100ths inch</param>
/// <param name="top">output top margin in 1/100ths inch</param>
/// <param name="right">output right margin in 1/100ths inch</param>
/// <param name="bottom">output bottom margin in 1/100ths inch</param>
public static void GetHardMargins(int hDc, ref float left, ref float top,
ref float right, ref float bottom)
{
float offx = Convert.ToSingle(GetDeviceCaps(hDc, PHYSICALOFFSETX));
float offy = Convert.ToSingle(GetDeviceCaps(hDc, PHYSICALOFFSETY));;
float resx = Convert.ToSingle(GetDeviceCaps(hDc, HORZRES));
float resy = Convert.ToSingle(GetDeviceCaps(hDc, VERTRES));
float hsz = Convert.ToSingle(GetDeviceCaps(hDc, HORZSIZE))/25.4f; //
screen width in inches
float vsz = Convert.ToSingle(GetDeviceCaps(hDc, VERTSIZE))/25.4f; //
screen height in inches
float ppix = resx/hsz;
float ppiy = resy/vsz;
left = (offx/ppix) * 100.0f;
top = (offy/ppix) * 100.0f;
bottom = top + (vsz * 100.0f);
right = left + (hsz * 100.0f);
}
}
}
========================snip====================== ====
"Jason Newell" <no****@nospam.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Ron,

If you don't mind, will you go ahead and post your code. I think I might
be needing to do something similar in the next few weeks and it may save
me some time. Thanks a lot.

Jason Newell
Ron Allen wrote:
Devin,
My guess would be that you are seeing the effect of the printer's
'hard margins'. Using FW 1.x the origin of the print area for print
preview is 0,0 of the bitmap but for the printer it is x,y where x and y
are the printer's hard margins respectively. You can search for
GetHardMargins in this ng to see some code to get around this. This is
basically PInvoke on GetDeviceCaps to get the margins followed by a
TranslateTransform on the Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBounds for the Graphics and do the transform if the
Height/Width of this is less than the page size.

If you can't find the actual code reply here and I'll post it again
(C#). If you are using VB.Net look in
microsoft.public.dotnet.languages.vb for a translation.

Ron Allen


------------------snip==============

Oct 21 '05 #5

P: n/a
Jason,
Note that you won't need this for FW 2.0 as you can get all these things
directly from the PrintDocument or Graphics with 2.0.

Ron Allen
"Jason Newell" <no****@nospam.com> wrote in message
news:Od**************@TK2MSFTNGP15.phx.gbl...
Ron,

Thank you very much. I saved your code and will evaluate it when I get to
the printing part of my application. Thanks again!

Jason Newell
Ron Allen wrote:
Jason,
Here is the code. Modify as desired. NOTE: I took out a lot of <summary>
blocks that make the constants compile without warnings. They just said
the same thing as the comments at the end.
====================snip=======================

Oct 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.