高质量的C#窗口打印 [英] printing C# window form with high quality

查看:139
本文介绍了高质量的C#窗口打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用c#窗口形式创建了发票,其中包含多个(90+)标签,这些标签从面板中的另一个表单中获取值,我必须在A4尺寸纸张上打印该表单。我能够在a4纸上打印表格,但文字和行不清楚,即它打印文本为点 - 点(褪色)。我正在使用位图打印表格,请告诉我如何提高标签控件上的文本质量(如果打印得像pdf / doc文件那样会更好)。

代码如下:

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),panel) 1.Size));

}

private void button2_Click(object sender,EventArgs e)

{

pd.Document = printDocument1;

DialogResult result = pd.ShowDialog();

if(result == DialogResult.OK)

{< br $> b $ b printDocument1.Print();

//docToPrint.Print();



}

}

上面的代码工作正常,但标签控件上的文本质量很差。

解决方案

Don''使用位图 - 使用 PrintDocument [ ^ ]。



您可以将所需物品直接打印到文件上它出现在纸上。该链接提供了一个示例。


要从HTML输入打印高质量的PDF文件,您可以使用 wkhtmltopdf [ ^ ],这是可执行程序 - 不是图书馆!我使用这个解决方案大约一年没有任何问题。

您还可以查看 WkHtmlToXSharp [ ^ ] .net包装,一些客户报告内存泄漏。

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.

解决方案

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.


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.


这篇关于高质量的C#窗口打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆