我用 PrinterSetupDialog 来操作,在自己机器上可以顺利的实现打印,但是一放到其他机器上运行,打印出来的就是一张白纸。请教一下 如何用API函数来实现打印,不是使用控件。这段就是我用控件打印的代码:
procedure TForm1.BitPrintClick(Sender: TObject);
var
strect:Trect; //定义打印输出矩形框的大小
temhi,temwd:integer;
begin
if Image2.Picture.Graphic=nil then exit; printersetupdialog1.execute;
if printdialog1.execute then
begin
temhi:=image2.Height;
temwd:=image2.width;
while(temhi<printer.pageheight/2 ) and(temwd<printer.pagewidth/2) do
//将图形放大到打印页面大小
begin
temhi:=temhi+temhi;
temwd:=temwd+temwd;
end;
with strect do //定义图形在页面上的中心位置输出
begin
left:=(printer.pagewidth-temwd)div 2;
top:=(printer.pageheight-temhi)div 2;
right:=left+temwd;
bottom:=top+temhi;
end;
with printer do
begin
begindoc;
canvas.stretchdraw(strect,Image2.Picture.Bitmap); //将放大的图形向打印机输出
enddoc;
end;
end;
end;
procedure TForm1.BitPrintClick(Sender: TObject);
var
strect:Trect; //定义打印输出矩形框的大小
temhi,temwd:integer;
begin
if Image2.Picture.Graphic=nil then exit; printersetupdialog1.execute;
if printdialog1.execute then
begin
temhi:=image2.Height;
temwd:=image2.width;
while(temhi<printer.pageheight/2 ) and(temwd<printer.pagewidth/2) do
//将图形放大到打印页面大小
begin
temhi:=temhi+temhi;
temwd:=temwd+temwd;
end;
with strect do //定义图形在页面上的中心位置输出
begin
left:=(printer.pagewidth-temwd)div 2;
top:=(printer.pageheight-temhi)div 2;
right:=left+temwd;
bottom:=top+temhi;
end;
with printer do
begin
begindoc;
canvas.stretchdraw(strect,Image2.Picture.Bitmap); //将放大的图形向打印机输出
enddoc;
end;
end;
end;
begin
TP:=TPrinter.Create;
TP.Canvas.Draw();
END;