《金质打印通》03年开始第一版,然后到V2.5源码版,好多年了,从06年之后基本没动。
做了一个订单自定义打印,于是做出如下效果来。
达到如下效果有两种方式:
1、用模板打印方式,支持XML
2、用程序方式
3、模板+程序方式
为了全大家理解打印的组成部分,特用图标作了说明。
现把实现方式,分享给大家!
附代码,需要的朋友可以参考。
注意:
如上效果,除了标题头前的那个图标,是在新增事件OnDrawPageSetup实现外,所有功能,在6年前共享的《金质打印通》之AnyReport下,完全一样。
- //调用金质打印通预览打印
- private void CallGoldPrinter(bool viewOrPrint)
- {
- //打印表格,实质,就是打印二维数据
-
- string[,] gridText = new string[this.DetailGrids[0].Rows.Count, 8];
- for (int i = 0; i < this.DetailGrids[0].Rows.Count; i++)
- {
- if (i < this.DetailGrids[0].Rows.Count - 1)
- {
- gridText[i, 0] = (i + 1).ToString();
- }
- else
- {
- gridText[i, 0] = "合计";
- }
- gridText[i, 1] = this.DetailGrids[0].Rows[i].Cells["品牌"].Text.ToString();
- gridText[i, 2] = this.DetailGrids[0].Rows[i].Cells["国标型号"].Text.ToString();
- gridText[i, 3] = this.DetailGrids[0].Rows[i].Cells["数量"].Text.ToString();
- gridText[i, 4] = this.DetailGrids[0].Rows[i].Cells["含税单价"].Text.ToString();
- gridText[i, 5] = this.DetailGrids[0].Rows[i].Cells["含税金额"].Text.ToString();
- gridText[i, 6] = this.DetailGrids[0].Rows[i].Cells["到货周期"].Text.ToString();
- gridText[i, 7] = this.DetailGrids[0].Rows[i].Cells["小注"].Text.ToString();
- }
- //清单、单据打印类
- GoldPrinter.GoldPrinterList gpl = new GoldPrinter.GoldPrinterList();
- //事件,方便自定义打印
- gpl.OnDrawPageSetup += new EventHandler<GoldPrinter.DrawPageSetupEventArgs>(gpl_OnDrawPageSetup);
- gpl.PageSetupManager.ShowPrinterArea = false; //指定画可参考有效区域
- gpl.PageSetupManager.PageMargins = new System.Drawing.Printing.Margins(50, 50, 50, 50); //页边距
- gpl.DocumentName = "采购订单打印";
- gpl.PageBreakSuperCols = true; //是否因列超宽分页
- gpl.DefaultRowHeight = 25; //明细行高
- gpl.PageSize = 10; //每页指定打多少行
- gpl.AllowPadEmptyLines = true; //不够PageSize,刚空行填充
- #region 主子标题...
- gpl.PageSetupManager.PrimaryTitle.Text = "北京元六鸿远电子技术有限公司";
- gpl.PageSetupManager.PrimaryTitle.Font = new Font("华文行楷", 22, FontStyle.Bold);
- gpl.PageSetupManager.PrimaryTitle.BorderFormat.BordersEdge = GoldPrinter.Drawing.BorderEdgeFlags.None;
- //gpl.PageSetupManager.PrimaryTitle.LineCount = 0; //主标题下划线,默认2条
- gpl.PageSetupManager.SubTitle.Text = "采 购 订 单";
- gpl.PageSetupManager.SubTitle.Font = new Font("华文中宋", 16, FontStyle.Bold);
- gpl.PageSetupManager.SubTitle.BorderFormat.BordersEdge = GoldPrinter.Drawing.BorderEdgeFlags.None;
- #endregion 主子标题...
- //多层表头
- gpl.TableTitleRowHeight = 35;
- #region 表格标题(多层表头)...
- gpl.TableTitleText = new string[1, 8];
- gpl.TableTitleText[0, 0] = "序号";
- gpl.TableTitleText[0, 1] = "品牌";
- gpl.TableTitleText[0, 2] = "型号规格";
- gpl.TableTitleText[0, 3] = "数量(支)";
- gpl.TableTitleText[0, 4] = "含税单价(元)";
- gpl.TableTitleText[0, 5] = "含税金额(元)";
- gpl.TableTitleText[0, 6] = "到货周期";
- gpl.TableTitleText[0, 7] = "备注";
- #endregion 表格标题(多层表头)...
- //表格主体明细
- gpl.TableText = gridText;
- gpl.TableFormat.TextFormat.Font = new Font("华文中宋", 11);
- gpl.TableInfo.ColsAlignment = new GoldPrinter.Drawing.HAlignFlag[] { GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Left, GoldPrinter.Drawing.HAlignFlag.Left, GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Left, GoldPrinter.Drawing.HAlignFlag.Left };
- //gpl.TableInfo.ColsAlignment = GoldPrinter.Drawing.HAlignFlag[]
- //{GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Right,GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Right,GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Right};
- //装订线
- gpl.PageSetupManager.Gutter.Text = "元 六 订 单 装 订 线";
- //页眉
- #region 页眉...
- gpl.PageSetupManager.HeaderMargin = 20;
- gpl.PageHeader.Align = GoldPrinter.Drawing.HAlignFlag.Right;
- gpl.PageHeader.LineVisible = false;
- gpl.PageHeader.Font = new Font("华文中宋", 11);
- gpl.PageHeader.Text = "文件号:YL-JL-JH-010-2011";
- #endregion 页眉...
- //页脚
- #region 页脚...
- gpl.PageSetupManager.FooterMargin = 20;
- gpl.PageFooter.Align = GoldPrinter.Drawing.HAlignFlag.Center;
- gpl.PageHeader.LineVisible = false;
- gpl.PageFooter.Font = new Font("华文中宋", 11);
- gpl.PageFooter.Text = "第[@PageIndex]页/共[@PageCount]页";
- #endregion 页脚...
- GoldPrinter.TablePrinterBase header = new GoldPrinter.TablePrinterBase();
- //表头个数不限,因此,无论是几行几列,是否规则,都可以打印
- #region 表头...
- gpl.PageSetupManager.SubTitle.Font = new Font("华文中宋", 12);
- header.TableText = new string[5, 4];
- header.TableFormat.DefaultRowHeight = 30;
- header.TableFormat.TextFormat.Font = new Font("华文中宋", 12);
- header.TableInfo.ColsWidth = new int[] { 100,250,100,250};
- header.TableFormat.GridLines = GoldPrinter.Drawing.GridLineFlag.None;
- header.TableText[0, 0] = "订货日期:";
- header.TableText[1, 0] = "供方单位:";
- header.TableText[2, 0] = "供方联系人:";
- header.TableText[3, 0] = "供方电话:";
- header.TableText[4, 0] = "供方传真:";
- header.TableText[0, 1] = "";
- header.TableText[1, 1] = "";
- header.TableText[2, 1] = "";
- header.TableText[3, 1] = "";
- header.TableText[4, 1] = "";
- header.TableText[0, 2] = "订单号:";
- header.TableText[1, 2] = "需方单位:";
- header.TableText[2, 2] = "需方联系人:";
- header.TableText[3, 2] = "需方电话:";
- header.TableText[4, 2] = "需方传真:";
- header.TableText[0, 3] = "";
- header.TableText[1, 3] = "";
- header.TableText[2, 3] = "";
- header.TableText[3, 3] = "";
- header.TableText[3, 3] = "";
- #endregion 表头...
- gpl.AddTableHeader(header);
- //页底签字
- GoldPrinter.TablePrinterBase footer = null;
- //表底,个数不限
- gpl.ColsWidth = new int[] { 40, 70, 230, 70, 95, 95, 70, 40 }; //列宽
- gpl.SpaceTableBodyFooter = 0; //金额大写与明细表,合为一体
- #region 表底(包括金额合计大写)...
- //金额合计
- footer = new GoldPrinter.TablePrinterBase();
- footer.TableFormat.TextFormat.Font = new Font("华文中宋", 12, FontStyle.Bold);
- footer.TableText = new string[1, 2];
- footer.TableFormat.DefaultRowHeight = 30;
- footer.TableInfo.ColsWidth = new int[] { 40+70+230+ 70, 95+95+70+40 }; //列宽
- footer.TableInfo.ColsAlignment = new GoldPrinter.Drawing.HAlignFlag[] { GoldPrinter.Drawing.HAlignFlag.Center, GoldPrinter.Drawing.HAlignFlag.Center };
- footer.TableText[0, 0] = "金额大小";
- if (this.DetailGrids[0].Rows.Count > 2 && this.DetailGrids[0].Rows[(this.DetailGrids[0].Rows.Count - 1)].Cells["含税金额"].Text != "")
- {
- footer.TableText[0, 1] = GoldPrinter.ChineseNum.GetUpperMoney(double.Parse(this.DetailGrids[0].Rows[(this.DetailGrids[0].Rows.Count - 1)].Cells["含税金额"].Text.ToString()));
- }
- else
- {
- footer.TableText[0, 1] = "";
- }
- gpl.AddTableFooter(footer);
- #region 页底签字...
- footer = new GoldPrinter.TablePrinterBase();
- footer.TableFormat.TextFormat.Font = new Font("华文中宋", 12, FontStyle.Bold);
- footer.TableText = new string[7, 2];
- footer.TableFormat.DefaultRowHeight = 30;
- footer.TableFormat.GridLines = GoldPrinter.Drawing.GridLineFlag.None;
- footer.IsAverageColsWidth = true;
- footer.TableText[0, 0] = "供方签字:";
- footer.TableText[1, 0] = "";
- footer.TableText[2, 0] = "";
- footer.TableText[3, 0] = "________________________";
- footer.TableText[4, 0] = "";
- footer.TableText[5, 0] = "";
- footer.TableText[6, 0] = "________________________";
- footer.TableText[0, 1] = "需方签字:";
- footer.TableText[1, 1] = "";
- footer.TableText[2, 1] = "制单人:________________________";
- footer.TableText[3, 1] = "";
- footer.TableText[4, 1] = "审核人:________________________";
- footer.TableText[5, 1] = "";
- footer.TableText[6, 1] = "批准人:________________________";
- gpl.AddTableFooter(footer);
- #endregion 页底签字...
- //页底 (备注)
- #region 页底备注...
- //GoldPrinter.TablePrinterBase = null;
- footer = new GoldPrinter.TablePrinterBase();
- footer.TableFormat.TextFormat.Font = new Font("华文中宋", 12);
- footer.TableText = new string[10, 1];
- footer.TableFormat.DefaultRowHeight = 30;
- footer.TableFormat.GridLines = GoldPrinter.Drawing.GridLineFlag.None;
- footer.IsAverageColsWidth = true; //只有一列,用平均宽,就是有效页宽了
- footer.TableText[0, 0] = "备注:";
- footer.TableText[1, 0] = " 1 合同签订地点及交货地点:需方所在地。";
- footer.TableText[2, 0] = " 2 运费负担:供方承担运费。";
- footer.TableText[3, 0] = " 3 产品包装:原厂包装。";
- footer.TableText[4, 0] = " 4 质量标准:产品质量必须符合相应品牌标准。";
- footer.TableText[5, 0] = " 5 付款方式:预付/货到付款。";
- footer.TableText[6, 0] = " 6 开具发票:以上单价含17%增值税,供方开具正规合法增值税发票。";
- footer.TableText[7, 0] = " 7 质量保证:如出现质量问题,由供方负责调换或退货,并承担相应的费用。";
- footer.TableText[8, 0] = " 8 违约责任:双方友好协商解决,协商未果依照中华人民共和国合同法执行。";
- footer.TableText[9, 0] = " 9 本合同一式两份,自签订之日起生效,传真件有效。";
- gpl.AddTableFooter(footer);
- #endregion 页底备注...
- #endregion 表底...
- if (viewOrPrint)
- {
- gpl.ShowPreview();
- }
- else
- {
- gpl.Print();
- }
- }
- void gpl_OnDrawPageSetup(object sender, GoldPrinter.DrawPageSetupEventArgs e)
- {
- System.Drawing.Image img = null;
- System.Drawing.Graphics g = e.Graphics;
- img = System.Drawing.Image.FromFile("Images\\UserLogo.bmp");
- g.DrawImage(img,125,50);
- }