Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need some help, guys.

I have an image that is to be printed on a page, and the problem is this.
Besides the image, I have to have on the page the borders printed as well.
What i tried to do is use the Graphics method DrawLine of the printpageEvents and draw four simple lines between the 4 points given by the set margins (), but I can't seem to get the lines drawn where they should be drawn. The whole image is either shifted right and down or instead of let's say the top border(line) being at 10mm from the top of the page, it's printed at 15mm...

Any ideas? It's driving me mad! Mad I Say!!

Thanks for your help.
Posted

Each printer has a minimum margin setting. Maybe 10mm smaller than your printer's minumum.

I googled "C# printing margins", and found this:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.margins.aspx[^]
 
Share this answer
 
v3
you can draw a rectangle using marginbounds of the page.
i.e. e.DrawRectangle(pen.black,e.marginbounds)
 
Share this answer
 
v2
Comments
RaviRanjanKr 7-Sep-11 5:29am    
Always wrap your code in "pre" tag or use Code tag to wrap select text.
public void Printing()
{
try
{
/* This assumes that a variable of type string, named filePath,
has been set to the path of the file to print. */
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
/* This assumes that a method, named pd_PrintPage, has been
defined. pd_PrintPage handles the PrintPage event. */
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
/* This assumes that a variable of type string, named
printer, has been set to the printer's name. */
pd.PrinterSettings.PrinterName = printer;
// Create a new instance of Margins with one inch margins.
Margins margins = new Margins(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred printing the file - " + ex.Message);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900