.NET Printing

  • Thread starter Thread starter CyberCyclist
  • Start date Start date
C

CyberCyclist

There are many good examples of printing using the
PrintDocument class. However, I can't find any mention of
printer offsets. For example, printing something at
100,100 will display in the print preview window one inch
(display inches) from the upper left corner. If the same
thing is sent to the printer, it is printed more than one
inch from the corner because most printers have a
printable area that doesn't go right to the edge. The
problem is that printers all have slightly different
printable areas. In VB 98, it was easy because you could
set the scale mode of the printer to inches and get a
scale width and height that was slightly smaller than the
width of the paper allowing you to adjust the margins.
Anyone know how to retrieve the printable area in .NET?

Thanks in advance
 
Hi,

There should be a PrinterSettings class or something similar - I definitely
remember I could get margins, orientation etc. in a WinForms application
which needed to do some printing.
 
You need to PInvoke GetDeviceCaps to get the exact printer hard margins
for offsets using the HDC of the Graphics being used. I have some C# code
that does this if you would like a copy.
You can approximate this by finding the difference between the
VisibleClipBounds and the page width/height and use 1/2 of the value. This
only works on printers with symmetrical hard margins though. A lot of ink
jet printers have varying hard margins and thus won't be exact using the
appoximation.
You can google in microsoft.public.dotnet.framework.drawing and find
more discussions of this and other printing issues.
Ron Allen
 
Thanks for the info. I thought I might have to use an API
call, but I wasn't sure how to do this in VB.NET.

Have a good day.
-----Original Message-----
You need to PInvoke GetDeviceCaps to get the exact printer hard margins
for offsets using the HDC of the Graphics being used. I have some C# code
that does this if you would like a copy.
You can approximate this by finding the difference between the
VisibleClipBounds and the page width/height and use 1/2 of the value. This
only works on printers with symmetrical hard margins though. A lot of ink
jet printers have varying hard margins and thus won't be exact using the
appoximation.
You can google in
microsoft.public.dotnet.framework.drawing and find
 
Using the VisibleClipBounds is like using the scalewidth
and scaleheight properties from VB 6 and is a good
approximation. However, I need some experience with API
calls in .NET so if you could send me your sample code for
GetDeviceCaps, it would be much appreciated. Either C# or
or VB will work.
-----Original Message-----
You need to PInvoke GetDeviceCaps to get the exact printer hard margins
for offsets using the HDC of the Graphics being used. I have some C# code
that does this if you would like a copy.
You can approximate this by finding the difference between the
VisibleClipBounds and the page width/height and use 1/2 of the value. This
only works on printers with symmetrical hard margins though. A lot of ink
jet printers have varying hard margins and thus won't be exact using the
appoximation.
You can google in
microsoft.public.dotnet.framework.drawing and find
 
(e-mail address removed)

Thanks
-----Original Message-----
You need to PInvoke GetDeviceCaps to get the exact printer hard margins
for offsets using the HDC of the Graphics being used. I have some C# code
that does this if you would like a copy.
You can approximate this by finding the difference between the
VisibleClipBounds and the page width/height and use 1/2 of the value. This
only works on printers with symmetrical hard margins though. A lot of ink
jet printers have varying hard margins and thus won't be exact using the
appoximation.
You can google in
microsoft.public.dotnet.framework.drawing and find
 
Back
Top