4、打印表头,我将表头的各个部分划成了几部分,如我的凭证打印的地方,我就划成了五部分,每部分按占百分比多少计算。如编制单位就占页面宽度的40%等
procedure tf_printpreview.printpageheader(pageheader: tstrings);
var
headrect:trect;
count:integer;
begin
pp_pz.printer.canvas.font.name:='宋体';
pp_pz.printer.canvas.font.color:=clblack;
pp_pz.printer.canvas.font.size:=9;
pp_pz.printer.canvas.font.style:=[];
gettextinfo;
amountprint:=amountprint+round(0.8*textheight);//当前逻辑尺的位置
for count:=0 to pageheader.count-1 do
begin
case count of
0:
headrect:=rect(round(pp_pz.printer.pageset.leftmargin),amountprint,round(pp_pz.printer.pageset.leftmargin+round(0.4*(pp_pz.printer.pagewidth))),amountprint+textheight);//编制单位比例
1:
headrect:=rect(headrect.right,amountprint,headrect.right+round(0.16*(pp_pz.printer.pagewidth)),amountprint+textheight);//凭证日期比例
2:
headrect:=rect(headrect.right,amountprint,headrect.right+round(0.14*(pp_pz.printer.pagewidth)),amountprint+textheight);//帐套号比例
3:
headrect:=rect(headrect.right,amountprint,headrect.right+round(0.2*(pp_pz.printer.pagewidth)),amountprint+textheight);//凭证号比例
4:
headrect:=rect(headrect.right,amountprint,headrect.right+round(0.1*(pp_pz.printer.pagewidth)),amountprint+textheight);//分页数号比例
end;
pp_pz.printer.canvas.textout(headrect.left,headrect.top,pageheader[count]);
end;
end;
5、打印表格头
procedure tf_mxzprint.printdetailheader(detailheader: tstrings);
var
drect,srect,jrect:trect;
begin
pp_pz.printer.canvas.font.name:='宋体';
pp_pz.printer.canvas.font.color:=clblack;
pp_pz.printer.canvas.font.size:=9;
pp_pz.printer.canvas.font.style:=[];
gettextinfo;
amountprint:=amountprint+textheight;
pp_pz.printer.canvas.font.size:=11;
drect:=rect(pagerect.left,amountprint,pagerect.left+round(0.3*(pagerect.right-pagerect.left)),amountprint+2*textheight);
drawtext(pp_pz.printer.canvas.handle,pchar('摘 要'),length('摘 要'),drect,dt_center or dt_wordbreak or dt_vcenter or dt_singleline);
addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
drect:=rect(drect.right,drect.top,drect.right+round(0.4*(pagerect.right-pagerect.left)),srect.bottom);
drawtext(pp_pz.printer.canvas.handle,pchar('科目名称'),length('科目名称'),drect,dt_center or dt_wordbreak or dt_vcenter or dt_singleline);
addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
drect:=rect(drect.right,drect.top,drect.right+round(0.15*(pagerect.right-pagerect.left)),srect.bottom);
drawtext(pp_pz.printer.canvas.handle,pchar('借方金额'),length('借方金额'),drect,dt_center or dt_wordbreak or dt_vcenter or dt_singleline);
addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom]);
drect:=rect(drect.right,drect.top,drect.right+round(0.15*(pagerect.right-pagerect.left)),srect.bottom);
addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
drawtext(pp_pz.printer.canvas.handle,pchar('贷方金额'),length('贷方金额'),drect,dt_center or dt_wordbreak or dt_vcenter or dt_singleline);
addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom]);
amountprint:=amountprint+drect.bottom-drect.top;//+textheight;
end;
5、打印表格内容
(与上面相似,代码太多,略。。。)
6、打印汇总栏内容(代码较多,而且也相似,略)
7、执行打印功能
pp_pz.printer.begindoc;
依次打印标题、打印、表头等
polypolyline(pp_pz.printer.canvas.handle,polypolypoints.list^,polylengths.list^,polylengths.count); pp_pz.printer.enddoc;
关键:就两个函数polypolyline和drawtext而已!
请注意,我这是连载,我发现我最后一贴看的人比较多,可光看这篇基本上看不出什么来的。管理员没有发表我的第一篇,我现在把第一篇放到了连(二)里面去了,所以大家不要找连载(一)了!由于时间比较忙,所以有一部分朋友要求要源码还没来的及整理,但我一整理出来我就会发过去的,谢谢大家!
好了,如果大家需要源码可以向我索取,yczyk@163.com