Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have created invoice in c# window form which contain multiple(90+) labels which takes values from another form in a panel and I have to print that form on a4 size paper. I am able to print the form on a4 paper but the text and the line are not clear i.e. it print text as dot-dot(faded). I am using bitmap to print the form please tell me how I can improve the quality of text on label control (If it print like pdf/doc file that will be better).
CODE is as follows :
private void printpreview_Click(object sender, EventArgs e)
{
ppd.Document = printDocument1;
ppd.ShowDialog();
}
private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
int x = e.MarginBounds.Left / 3 + 10;
int y = e.MarginBounds.Top / 2;
Bitmap image = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(image, new Rectangle(new Point(), panel1.Size));
Graphics g = e.Graphics;
g.PageUnit = GraphicsUnit.Display;
g.DrawImage(image, new Rectangle(new Point(x, y), panel1.Size));
}
private void button2_Click(object sender, EventArgs e)
{
pd.Document = printDocument1;
DialogResult result = pd.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
//docToPrint.Print();

}
}
The above code is working properly but quality of text on label control is very poor.
Posted
Updated 26-Feb-13 2:43am
v2
Comments
Matej Hlatky 26-Feb-13 8:13am    
Print a form into paper? You can't be serious.

Don't use a bitmap - use a PrintDocument[^] instead.

You print the items you need directly onto the Document and it comes out on paper. The link provides an example.
 
Share this answer
 
Comments
Member 9793793 26-Feb-13 9:01am    
can you pls tell me how in above code
OriginalGriff 26-Feb-13 9:22am    
No, no - don't use a bitmap.
If you want to print the panel content, then read the items on the panel, and print them on the PrintDocument at the places you want them for the customer to read! If you convert the Panel to a bitmap image, it will be at screen resolution, which may be completely useless when printed.
Member 9793793 26-Feb-13 9:27am    
hi This is first time I am doing so I don't have much knowledge please can you explain it with example or modify my code.
OriginalGriff 26-Feb-13 10:31am    
Follow the link - it has an example!
Member 9793793 27-Feb-13 4:24am    
Hi i have tried this but I am getting an error "Object reference not set to an instance of an object."(Null reference exception was unhandled) on this line.
for (int i = 1; i <= 63; i++)
{
int x = labeltxt[i].Location.X; // this line shows error
int y = labeltxt[i].Location.Y;
printtxt[i] = labeltxt[i].Text ;
g.DrawString(printtxt[i], new Font("Microsoft Sans Serif", 8), Brush, x, y);
}
For printing high-quality PDF files from HTML input you can use wkhtmltopdf[^], which is executable program - not library!. I am using this solution circa one year without any problems.
You can also have a look at the WkHtmlToXSharp[^] .net wrapper, byt some clients reported memory leaks.
 
Share this answer
 
v2

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