flyingboat: 我是自己写代码打印的。下面的代码时打印一页。
主调程序负责初始化xdpi,ydpi(打印机的水平和垂直分辨率),
Printer.begin
Doc
Printer.Title := '呵呵';
for i := startpage to endpagedo
begin
PrintOnePage(i);
if not endpage then
Printer.Newpage
end;
Printer.EndDoc;
支持页眉和页脚,参考参考吧
procedure PrintOnePage(pgno: Integer);
var
i, j: Integer;
ltp: Integer;
gw, gh: Integer;
sx, sy: Integer;
yh, yf: Integer;
TmpStr: String;
begin
with Printer, Printer.Canvasdo
begin
if pgno=PageCnt then
ltp := RcdCnt mod LineCnt//LineCnt为主调程序算出每页能达到少行
else
ltp := LineCnt;//决定每页该打多少条记录
if ltp=0 then
ltp := LineCnt;
gw := Round(593/96*xdpi);//报表输出宽度
gh := Round(20/96*(ltp+1)*ydpi);//报表输出高度
sx := (PageWidth - gw) div 2;//居中
sy := Round(MainForm.MarginTop/254*ydpi);//左边距
yh := Round(MainForm.MarginHead/254*ydpi);//页眉距
yf := Round(MainForm.MarginFoot/254*ydpi);//页脚距
Pen.Width := Round(xdpi/48);//线粗
Brush.Style := bsSolid;
Rectangle(sx,sy,sx+gw+1,sy+gh+Pen.Width);//报表外框
Pen.Width := Round(xdpi/96);
for i := 1 to ltpdo
begin
MoveTo(sx,sy+Round(i*20/96*ydpi));
LineTo(sx+gw,sy+Round(i*20/96*ydpi));
end;
//报表每行分割线
for i := 1 to 7do
begin
MoveTo(sx+Round(xPos
/96*xdpi),sy);
LineTo(sx+Round(xPos/96*xdpi),sy+gh);
end;
//报表每列分割线
SetBkMode(Handle,TRANSPARENT);//透明模式
Font.Name := MainForm.HeadFont;
Font.Size := 15;
i := TextWidth(TitleStr);
TextOut(sx+(gw-i)div 2,yh,TitleStr);//输出页眉
Font.Name := MainForm.TextFont;
Font.Size := 9;
for i := 0 to 7do
TextOut(sx+Round((xPos+2)/96*xdpi),
sy+Round(5/96*ydpi),
DataModule1.Table1.Fields.DisplayLabel);//输出报表字段
DataModule1.Table1.First;
DataModule1.Table1.MoveBy((pgno-1)*LineCnt);
for j := 1 to ltpdo
begin
for i := 0 to 7do
TextOut(sx+Round((xPos+2)/96*xdpi),
sy+Round(j*20/96*ydpi)+Round(5/96*ydpi),
DataModule1.Table1.Fields.AsString);
DataModule1.Table1.Next;
end;
//输出该页的记录
Font.Name := MainForm.FootFont;
Font.Size := 8;
TmpStr := Format('第%d页',[pgno]);
i := TextWidth(TmpStr);
j := TextHeight(TmpStr);
TextOut(sx+(gw-i)div 2,PageHeight-yf-j,TmpStr);//输出页脚
end;
end;