public PrinterHint GetHeader(int pagewidth, string text) { int captionHeight = 45; Font font = new Font("宋体", 20); Graphics g = this.button1.CreateGraphics(); int height = (int)g.MeasureString(text, font).Height; int width = (int)g.MeasureString(text, font).Width; g.Dispose(); PrinterHint header = new PrinterHint(); header.Rectangle = new Rectangle(0, 0, pagewidth, height + captionHeight + 12); header.PrintInEveryPage = true; header.Border = BordersEdgeStyle.None; TitleDraw title = new TitleDraw(text); title.Font = font; title.Rectangle = new Rectangle((pagewidth - width) / 2, 0, width, height); title.Border = BordersEdgeStyle.Bottom; TitleDraw line = new TitleDraw(""); line.Rectangle = new Rectangle((pagewidth - width) / 2, 2, width, height); line.Border = BordersEdgeStyle.Bottom; header.Add(title); header.Add(line); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Far; Font cap = new Font("宋体", 14); TextDraw header2 = new TextDraw("培训单位: 报考车型: 考试日期: 年 月 日"); header2.Formater = sf; header2.Font = cap; header2.Rectangle = new Rectangle(0, height + 7, pagewidth, captionHeight); header2.Border = BordersEdgeStyle.None; CompanyInfo compInfo = StaticCacheManager.GetConfig <CompanyInfo>(); TextDraw comp = new TextDraw(compInfo.NickName); comp.Formater = sf; comp.Font = cap; comp.Rectangle = new Rectangle(100, height + 7, 200, captionHeight); comp.Border = BordersEdgeStyle.None; header.Add(comp); header.Add(header2); return(header); }
protected virtual PrinterHint BuildHeader() { StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Far; sf.Alignment = StringAlignment.Far; StringFormat sf2 = new StringFormat(); sf2.LineAlignment = StringAlignment.Center; sf2.Alignment = StringAlignment.Center; CompanyInfo comp = StaticCacheManager.GetConfig<CompanyInfo>(); int pagewidth = customMargin.Width; int captionHeight = 70; Font font = new Font("宋体", 20); Font cap = new Font("宋体", 14); int height = 25; PrinterHint header = new PrinterHint(); header.Rectangle = new Rectangle(0, 0, pagewidth, height + captionHeight + 12); header.PrintInEveryPage = false; header.Border = BordersEdgeStyle.None; //打印单位名称 TitleDraw title = new TitleDraw(comp.NickName+" "+System.DateTime.Now.ToShortDateString()); title.Font = cap; title.Rectangle = new Rectangle(0, 0, pagewidth, height); title.Border = BordersEdgeStyle.None; title.Formater = sf; //打印主标题 TitleDraw titleMain = new TitleDraw(this.headerTitle); titleMain.Font = font; titleMain.Rectangle = new Rectangle(0, height, pagewidth, captionHeight); titleMain.Border = BordersEdgeStyle.None; titleMain.Formater = sf2; header.Add(title); header.Add(titleMain); return header; }
public PrinterHint GetFooter(int pageWidth) { Font font = new Font("宋体", 15); PrinterHint footer = new PrinterHint(); footer.Border = BordersEdgeStyle.None; footer.Rectangle = new Rectangle(-2, 0, pageWidth + 2, 147); /*有时候不打线出来*/ //RecetangleDraw outer = new RecetangleDraw(); TextDraw outer = new TextDraw(" "); outer.Font = font; outer.Border = BordersEdgeStyle.All; outer.Rectangle = new Rectangle(-1, 0, pageWidth + 2, 3 * 34); TextDraw inner = new TextDraw(" "); inner.Font = font; inner.Border = BordersEdgeStyle.All; //RecetangleDraw inner = new RecetangleDraw(); inner.Rectangle = new Rectangle(2, 3, pageWidth - 4, 3 * 34 - 5); /*有时候不打线出来*/ footer.Add(outer); footer.Add(inner); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; TextDraw txt1 = new TextDraw("报考员"); txt1.Font = font; txt1.Rectangle = new Rectangle(2, 3, footerWidth, footer1Height); txt1.Border = BordersEdgeStyle.Right; txt1.Formater = sf; footer.Add(txt1); TextDraw txt2 = new TextDraw("签名"); txt2.Font = font; txt2.Rectangle = new Rectangle(2, footer1Height + 3, footerWidth, footer1Height); txt2.Border = BordersEdgeStyle.Right; txt2.Formater = sf; footer.Add(txt2); RecetangleDraw space1 = new RecetangleDraw(); space1.Rectangle = new Rectangle(2 + footerWidth, 3, spaceWidth, 2 * footer1Height); space1.Border = BordersEdgeStyle.Right; footer.Add(space1); TextDraw txt3 = new TextDraw("主考员"); txt3.Font = font; txt3.Rectangle = new Rectangle(2 + spaceWidth + footerWidth, 3, footerWidth, footer1Height); txt3.Border = BordersEdgeStyle.Right; txt3.Formater = sf; footer.Add(txt3); TextDraw txt4 = new TextDraw("签名"); txt4.Font = font; txt4.Rectangle = new Rectangle(2 + spaceWidth + footerWidth, footer1Height + 3, footerWidth, footer1Height); txt4.Border = BordersEdgeStyle.Right; txt4.Formater = sf; footer.Add(txt4); RecetangleDraw space2 = new RecetangleDraw(); space2.Rectangle = new Rectangle(2 + 2 * footerWidth + spaceWidth, 3, spaceWidth, 2 * footer1Height); space2.Border = BordersEdgeStyle.Right; footer.Add(space2); TextDraw txt5 = new TextDraw("助考员"); txt5.Font = font; txt5.Rectangle = new Rectangle(2 + 2 * (spaceWidth + footerWidth), 3, footerWidth, footer1Height); txt5.Border = BordersEdgeStyle.Right; txt5.Formater = sf; footer.Add(txt5); TextDraw txt6 = new TextDraw("签名"); txt6.Font = font; txt6.Rectangle = new Rectangle(2 + 2 * (spaceWidth + footerWidth), footer1Height + 3, footerWidth, footer1Height); txt6.Border = BordersEdgeStyle.Right; txt6.Formater = sf; footer.Add(txt6); RecetangleDraw space3 = new RecetangleDraw(); space3.Rectangle = new Rectangle(2 + 3 * footerWidth + 2 * spaceWidth, 3, spaceWidth - 10, footer1Height * 2); space3.Border = BordersEdgeStyle.Right; footer.Add(space3); TextDraw txt7 = new TextDraw("审核人"); txt7.Font = font; txt7.Rectangle = new Rectangle(2 + 3 * (spaceWidth + footerWidth) - 10, 3, footerWidth - 6, footer1Height * 2); txt7.Border = BordersEdgeStyle.Right; txt7.Formater = sf; footer.Add(txt7); TextDraw txt8 = new TextDraw("报考人数:_______"); txt8.Font = font; txt8.Rectangle = new Rectangle(2, 3 + 2 * footer1Height, footerWidth2, 45); footer.Add(txt8); TextDraw txt9 = new TextDraw("合格人数:_______"); txt9.Font = font; txt9.Rectangle = new Rectangle(2 + footerWidth2, 3 + 2 * footer1Height, footerWidth2, 45); footer.Add(txt9); TextDraw txt10 = new TextDraw("不合格人数:_____"); txt10.Font = font; txt10.Rectangle = new Rectangle(2 + 2 * footerWidth2, 3 + 2 * footer1Height, footerWidth2, 45); footer.Add(txt10); TextDraw txt11 = new TextDraw("缺考人数:______"); txt11.Font = font; txt11.Rectangle = new Rectangle(2 + 3 * footerWidth2, 3 + 2 * footer1Height, pageWidth - 4 - 3 * footerWidth2, 45); footer.Add(txt11); TextDraw text = new TextDraw(" 注:此表填写不全,不予受理。填写内容涂改无效。"); text.Border = BordersEdgeStyle.None; text.Font = font; text.Rectangle = new Rectangle(0, 102, pageWidth, 40); footer.Add(text); footer.PrintInEveryPage = true; return(footer); }