473,785 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2242
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 TranslateTransf orm on the
Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBoun ds 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.publi c.dotnet.langua ges.vb
for a translation.

Ron Allen

"Devin Dow" <De*******@rs i-inc.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.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 TranslateTransf orm on the
Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBoun ds 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.publi c.dotnet.langua ges.vb
for a translation.

Ron Allen

"Devin Dow" <De*******@rs i-inc.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.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*******@r si-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("gdi3 2.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">Inpu t handle</param>
/// <param name="left">out put left margin in 1/100ths inch</param>
/// <param name="top">outp ut top margin in 1/100ths inch</param>
/// <param name="right">ou tput right margin in 1/100ths inch</param>
/// <param name="bottom">o utput 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.ToSingl e(GetDeviceCaps (hDc, PHYSICALOFFSETX ));
float offy = Convert.ToSingl e(GetDeviceCaps (hDc, PHYSICALOFFSETY ));;
float resx = Convert.ToSingl e(GetDeviceCaps (hDc, HORZRES));
float resy = Convert.ToSingl e(GetDeviceCaps (hDc, VERTRES));
float hsz = Convert.ToSingl e(GetDeviceCaps (hDc, HORZSIZE))/25.4f; //
screen width in inches
float vsz = Convert.ToSingl e(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******** ******@TK2MSFTN GP10.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
TranslateTransf orm on the Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipBoun ds 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.publi c.dotnet.langua ges.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("gdi3 2.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">Inpu t handle</param>
/// <param name="left">out put left margin in 1/100ths inch</param>
/// <param name="top">outp ut top margin in 1/100ths inch</param>
/// <param name="right">ou tput right margin in 1/100ths inch</param>
/// <param name="bottom">o utput 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.ToSingl e(GetDeviceCaps (hDc, PHYSICALOFFSETX ));
float offy = Convert.ToSingl e(GetDeviceCaps (hDc, PHYSICALOFFSETY ));;
float resx = Convert.ToSingl e(GetDeviceCaps (hDc, HORZRES));
float resy = Convert.ToSingl e(GetDeviceCaps (hDc, VERTRES));
float hsz = Convert.ToSingl e(GetDeviceCaps (hDc, HORZSIZE))/25.4f; //
screen width in inches
float vsz = Convert.ToSingl e(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******** ******@TK2MSFTN GP10.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
GetHardMargi ns in this ng to see some code to get around this. This is
basically PInvoke on GetDeviceCaps to get the margins followed by a
TranslateTra nsform on the Graphics.
I normally check to see if this needs to be done by checking the
VisibleClipB ounds 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.pu blic.dotnet.lan guages.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******** ******@TK2MSFTN GP15.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
2815
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: Undefined variable PHP Notice: Undefined index PHP Notice: Undefined property I'd like to go back and fix what I can, but I'm wondering: how good or bad is this? I mean, I rely on the fact that the first use of a variable
23
63698
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 vars, along with their names. I could easily do this: print "myPlace = %s, myTime = %s" % (myPlace, myTime)
1
5244
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 not the best way to do it). If I have multiple pages, everything works just fine. For some reason that I can't figure out, when I only have a single page, IE when it goes to print (print preview included), will add a second blank page, regardless...
53
4603
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, and at the end there is even pure mindstorming text left in, but already I think it can be very useful. <url: http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01__alpha.doc.pdf>.
39
7664
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 indicate: a) That I don't know enough b) Passing arguments by ref is bad
5
303
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 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
22
130420
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 document and closes it with the following code: <body onload="window.print(); window.close();"> This works correctly (or at least the way I expect it to work under MS Internet Explorer, but it cuases Netscape to "crash"
10
1551
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 decided?
9
3082
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 command button is clicked for good or bad parts. When the container is filled with good parts, the operator manualy clicks a command button to print a report (container label). I have been asked to automate the container label report so it prints when...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.