473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Print Preview=GOOD, Printout=BAD

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
5 2196
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Coder Droid | last post by:
I decided to run some code with errors set to E_ALL, just to see what I would run across. It caught a few things, but 90% or better of the messages were of the 'undefined' kind: PHP Notice: ...
23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
1
by: Benjamin | last post by:
I have a weird behavior occuring in IE 6.0. I am trying to use HTML to display documents to a user, but then also have it sent directly to the printer and have it look similiar (I know probably...
53
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
5
by: Devin Dow | last post by:
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...
22
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the...
10
by: James Thiele | last post by:
I noticed in PEP 3000 that print will become a function. The PEP references a thread where Guido explains this decision. The thread does not specify what the function will return. Has this been...
9
by: larryimic | last post by:
I have created a Access production database that records good parts and bad parts to a table thru querys using macros and command buttons on a form. A report (part label) is printed each time a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.