用微软自带五件套
//定义边界 设置纸张大小 注意 335 (纸张的宽度,以百分之一英寸为单位)
Margins margin = new Margins(0, 0, 0, 0);
printDocument1 = new PrintDocument();
printDocument1.DefaultPageSettings.Margins = margin;
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("热敏纸", 355, 119);
printDocument1.PrintPage += new PrintPageEventHandler(PrintPageEvent);
printDocument1.PrintController = controler;
printDocument1.Print();
public void PrintPageEvent(object Sender, PrintPageEventArgs e)
{
//设置字体样式
Font titleFont = new Font("黑体", 44, System.Drawing.FontStyle.Bold);//标题字体
Font fntTxt = new Font("宋体", 11, System.Drawing.FontStyle.Underline);//正文带下划线
Font smallFont = new Font("宋体", 8, System.Drawing.FontStyle.Underline);//正文带下划线
Font smallFont1 = new Font("宋体", 8, System.Drawing.FontStyle.Underline);//正文带下划线
Font smallFont2 = new Font("宋体", 11, System.Drawing.FontStyle.Underline);//正文带下划线
Font fntTxt1 = new Font("宋体", 11, System.Drawing.FontStyle.Regular);//正文文字
System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);//画刷
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);
//根据位置画文字
e.Graphics.DrawString("标识", fntTxt1, brush, new System.Drawing.Point(3, 8));
e.Graphics.DrawString("名称", fntTxt1, brush, new System.Drawing.Point(3, 36));
e.Graphics.DrawString("型号", fntTxt1, brush, new System.Drawing.Point(3, 64));
e.Graphics.DrawString("日期", fntTxt1, brush, new System.Drawing.Point(3, 92));
if (_xfbsh.Length > 29)
{
smallFont2 = new Font("宋体", 8, System.Drawing.FontStyle.Regular);//正文文字
}
//if (_cpmc.Length > 29)
//{
// smallFont = new Font("宋体", 8, System.Drawing.FontStyle.Regular);//正文文字
//}
//if (_ggxh.Length > 29)
//{
// smallFont1 = new Font("宋体", 8, System.Drawing.FontStyle.Regular);//正文文字
//}
e.Graphics.DrawString(_xfbsh, smallFont2, brush, new System.Drawing.Point(40, 8));
e.Graphics.DrawString(_cpmc, smallFont, brush, new System.Drawing.Point(40, 36));
// e.Graphics.DrawString(_ggxh, smallFont1, brush, new System.Drawing.Point(40, 64));
RectangleF descRect = new RectangleF();
using (Font useFont = new Font("宋体", 8, System.Drawing.FontStyle.Regular))
{
descRect.Location = new Point(40, 64);
descRect.Size = new Size(240, 40);
e.Graphics.DrawString(_ggxh, smallFont1, Brushes.Black, descRect);
}
e.Graphics.DrawString(_scrq, fntTxt, brush, new System.Drawing.Point(40, 92));
Bitmap bitmap = CreateQRCode(_cCode);
e.Graphics.DrawImage(bitmap, 275, 8, 60, 60);
e.Graphics.DrawString(_dw, fntTxt1, brush, new System.Drawing.Point(240, 92));
// e.Graphics.DrawImage(bitmap, new System.Drawing.Point(70, 2));
}
效果图