这里是发票管理及打印系统的部分代码,不才,献丑了,有需要的可以参考一下
代码
PrinterSettings printerSets = new PrinterSettings();
PageSettings pageSets = new PageSettings();
private void printdoc_PrintPage(object sender, PrintPageEventArgs e)
{
XmlDocument _xdoc = new XmlDocument();
_xdoc.LoadXml(this.printFaPiaoXml);
PrintDrawString(e, 0, 65, _xdoc.SelectSingleNode("/row/开票日期").InnerText.Trim());
PrintDrawString(e, 0, 275, fapiaoSets.行业);
PrintDrawString(e, 2, 0, "付款方:" + _xdoc.SelectSingleNode("/row/付款方").InnerText.Trim()); //河南新互联通信服务咨询有限公司
PrintDrawString(e, 2, 370, "付款方纳税人识别号:" + _xdoc.SelectSingleNode("/row/付款方税号").InnerText.Trim());
PrintDrawString(e, 3, 0, "收款方:" + fapiaoSets.收款方);
PrintDrawString(e, 3, 370, "收款方纳税人识别号:" + fapiaoSets.收款方税号);
PrintDrawString(e, 4, 0, "项目明细");
PrintDrawString(e, 5, 0, "项目");
PrintDrawString(e, 5, 260, "金额");
PrintDrawString(e, 5, 400, "备注");
int i = 6;
foreach (XmlNode node in _xdoc.SelectNodes("/row/项目明细/项目"))
{
PrintDrawString(e, i, 0, node.InnerText.Trim());
PrintDrawString(e, i, 260, node.Attributes["金额"].Value.Trim());
PrintDrawString(e, i, 400, node.Attributes["备注"].Value.Trim());
i++;
}
PrintDrawString(e, 13, 0, "合计人民币(大写):" + MoneyConvertChinese.MoneyToChinese(_xdoc.SelectSingleNode("/row/金额合计").InnerText.Trim()));
PrintDrawString(e, 13, 380, "合计人民币(小写):CNY" + _xdoc.SelectSingleNode("/row/金额合计").InnerText.Trim());
//PrintDrawString(e, 13, 600, "付款方式:" + "现金");
PrintDrawString(e, 15, 0, "开票人:" + fapiaoSets.开票人);
PrintDrawString(e, 15, 150, "审核人:" + fapiaoSets.审核人);
PrintDrawString(e, 16, 0, "主管税务机关:" + fapiaoSets.主管税务机关);
}
/// <summary>
/// 处理打印文字
/// </summary>
/// <param name="e">PrintPageEventArgs</param>
/// <param name="lineIndex">行号</param>
/// <param name="PointX">X轴偏移量</param>
/// <param name="drawString">文字</param>
private void PrintDrawString(PrintPageEventArgs e, int lineIndex, int PointX, string drawString)
{
//Y轴预设偏移量
int defaultY = 110;
//X轴预设偏移量
int defaultX = 60;
//行距
int defaultLineHeight = 22;
e.Graphics.DrawString(drawString, new Font("KaiTi_GB2312", 10), Brushes.Black, new PointF(defaultX + PointX, defaultY + (lineIndex * defaultLineHeight)));
}
/// <summary>
/// 打印前事件,设定打印参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void printdoc_BeginPrint(object sender, PrintEventArgs e)
{
this.pageSets.PrinterSettings.PrinterName = getPrinterName();
this.pageSets.PaperSize = this.fapiaoSize;
this.pageSets.Landscape = false;
this.printerSets.DefaultPageSettings.PaperSize = this.pageSets.PaperSize;
this.printerSets.PrinterName = getPrinterName();
this.printdoc.DocumentName = "机打发票";
this.printdoc.DefaultPageSettings = this.pageSets;
this.printdoc.PrinterSettings = this.printerSets;
}
PageSettings pageSets = new PageSettings();
private void printdoc_PrintPage(object sender, PrintPageEventArgs e)
{
XmlDocument _xdoc = new XmlDocument();
_xdoc.LoadXml(this.printFaPiaoXml);
PrintDrawString(e, 0, 65, _xdoc.SelectSingleNode("/row/开票日期").InnerText.Trim());
PrintDrawString(e, 0, 275, fapiaoSets.行业);
PrintDrawString(e, 2, 0, "付款方:" + _xdoc.SelectSingleNode("/row/付款方").InnerText.Trim()); //河南新互联通信服务咨询有限公司
PrintDrawString(e, 2, 370, "付款方纳税人识别号:" + _xdoc.SelectSingleNode("/row/付款方税号").InnerText.Trim());
PrintDrawString(e, 3, 0, "收款方:" + fapiaoSets.收款方);
PrintDrawString(e, 3, 370, "收款方纳税人识别号:" + fapiaoSets.收款方税号);
PrintDrawString(e, 4, 0, "项目明细");
PrintDrawString(e, 5, 0, "项目");
PrintDrawString(e, 5, 260, "金额");
PrintDrawString(e, 5, 400, "备注");
int i = 6;
foreach (XmlNode node in _xdoc.SelectNodes("/row/项目明细/项目"))
{
PrintDrawString(e, i, 0, node.InnerText.Trim());
PrintDrawString(e, i, 260, node.Attributes["金额"].Value.Trim());
PrintDrawString(e, i, 400, node.Attributes["备注"].Value.Trim());
i++;
}
PrintDrawString(e, 13, 0, "合计人民币(大写):" + MoneyConvertChinese.MoneyToChinese(_xdoc.SelectSingleNode("/row/金额合计").InnerText.Trim()));
PrintDrawString(e, 13, 380, "合计人民币(小写):CNY" + _xdoc.SelectSingleNode("/row/金额合计").InnerText.Trim());
//PrintDrawString(e, 13, 600, "付款方式:" + "现金");
PrintDrawString(e, 15, 0, "开票人:" + fapiaoSets.开票人);
PrintDrawString(e, 15, 150, "审核人:" + fapiaoSets.审核人);
PrintDrawString(e, 16, 0, "主管税务机关:" + fapiaoSets.主管税务机关);
}
/// <summary>
/// 处理打印文字
/// </summary>
/// <param name="e">PrintPageEventArgs</param>
/// <param name="lineIndex">行号</param>
/// <param name="PointX">X轴偏移量</param>
/// <param name="drawString">文字</param>
private void PrintDrawString(PrintPageEventArgs e, int lineIndex, int PointX, string drawString)
{
//Y轴预设偏移量
int defaultY = 110;
//X轴预设偏移量
int defaultX = 60;
//行距
int defaultLineHeight = 22;
e.Graphics.DrawString(drawString, new Font("KaiTi_GB2312", 10), Brushes.Black, new PointF(defaultX + PointX, defaultY + (lineIndex * defaultLineHeight)));
}
/// <summary>
/// 打印前事件,设定打印参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void printdoc_BeginPrint(object sender, PrintEventArgs e)
{
this.pageSets.PrinterSettings.PrinterName = getPrinterName();
this.pageSets.PaperSize = this.fapiaoSize;
this.pageSets.Landscape = false;
this.printerSets.DefaultPageSettings.PaperSize = this.pageSets.PaperSize;
this.printerSets.PrinterName = getPrinterName();
this.printdoc.DocumentName = "机打发票";
this.printdoc.DefaultPageSettings = this.pageSets;
this.printdoc.PrinterSettings = this.printerSets;
}