Re: Printing the whole whole printable area
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 18 Jun 2007 14:51:20 -0700
On Mon, 18 Jun 2007 13:11:13 -0700, Abhay <abhayjoukani@xxxxxxxxx> wrote:
Note that, just as is the case in on-screen graphics, the coordinate
system is relative to a virtual grid and your rectangle's lines are drawn
just to the right and below of the intersection on this grid defined by
the coordinates of a given point. This means that the right and bottom of
your rectangle are being drawn just outside of the printable area. You
need to inset the right and bottom by a pixel to get the line into the
boundary of the printable area.
Thanks for your reply Peter but that is not the case according to me
What I wrote certainly is true. Whether it's the cause of your problem, I can't say. You might have other problems too. There are a variety of issues that can cause graphics to not be drawn, whether to a printed page or the screen, and you haven't offered enough details about your specific problem for me to know for sure what it might be.
For example, what is the value of the OriginAtMargins property of the PrintDocument? What are the actual margins in your second test? What resolution is the printer set to? What print driver are you using?
But at the very least, you need to understand that if you try to draw a rectangle that is the same exact width and height as what you believe to be the valid area for drawing, the right and bottom edges will not be drawn.
For the record, the following code, when I use it with the Office Document Image Writer print driver (a convenient way to test printing code), it prints a frame exactly the way you want (assuming the margins are within the printable area, of course):
private void PrintPageHandler(object sender, PrintPageEventArgs ppea)
{
Rectangle rectFrame = new Rectangle(ppea.MarginBounds.Location,
new Size(ppea.MarginBounds.Width - 1, ppea.MarginBounds.Height - 1));
using (Pen penFrame = new Pen(Color.Black, 0.0f))
{
ppea.Graphics.DrawRectangle(penFrame, rectFrame);
}
ppea.HasMorePages = false;
}
If you happen to run into a print driver that for some reason doesn't work well with .NET and somehow having the Graphics units set to 100ths of an inch cause some sort of rounding error, you could do something like this:
private void PrintPageHandler(object sender, PrintPageEventArgs ppea)
{
float dpiX = ppea.PageSettings.PrinterResolution.X,
dpiY = ppea.PageSettings.PrinterResolution.Y;
RectangleF rcfFrame = new RectangleF(dpiX * ppea.MarginBounds..Left / 100.0f,
dpiY * ppea.MarginBounds.Top / 100.0f,
dpiX * ppea.MarginBounds.Width / 100.0f - 1,
dpiY * ppea.MarginBounds.Height / 100.0f - 1);
ppea.Graphics.PageUnit = GraphicsUnit.Pixel;
using (Pen penFrame = new Pen(Color.Black, 0.0f))
{
ppea.Graphics.DrawRectangle(penFrame, rcfFrame.Left, rcfFrame.Top, rcfFrame.Width, rcfFrame.Height);
}
ppea.HasMorePages = false;
}
I tested both versions with the Office Document Image Writer, and they both draw a complete rectangle, while not subtracting 1 from the width and height results in the right and bottom edge of the rectangle not being drawn.
i tried to reduce the pixel by 1 (around 15 infact) then to it dose'nt
show me the RIGHT and the BOTTOM margin
eg :- if the printable area is (Left,Top,Right,Bottom) :-
(16,16,818,1068) i have to reduce it to say (16,16,803,1053) then only
it prints out the rectangle correctly
The fact that the amount you have to reduce the rectangle is practically the same as the width of your margins suggests to me that you have somehow gotten a situation where the offset of the drawn rectangle isn't what you expect it to be. You could test this by drawing to a location left and above what you think is the correct place (for example, use the rectangle (0,0,818,1068) instead). In any case, I've offered about as much as I can think of that would be useful. If that doesn't help you fix the problem, I'm sorry for not being able to help.
Pete
.
- References:
- Printing the whole whole printable area
- From: Abhay
- Re: Printing the whole whole printable area
- From: Abhay
- Re: Printing the whole whole printable area
- From: Peter Duniho
- Re: Printing the whole whole printable area
- From: Abhay
- Printing the whole whole printable area
- Prev by Date: Re: using System.Management a faux pas?
- Next by Date: Re: using System.Management a faux pas?
- Previous by thread: Re: Printing the whole whole printable area
- Next by thread: need help!
- Index(es):
Relevant Pages
|