给你一个我做的函数,在开始打印时加入就可以生成你要的纸张了。不过你得自己判断是
不是NT类型的操作系统,这个太多了,我就不贴了
//向打印服务器中加入自定义纸张,适用于win nt/2000/xp
uses 中引用:Printers,winspool;
参数说明:
PaperName: 纸张名称,PaperWidth:纸张宽度,PaperHeigth:纸张高度,单位为厘米
返回值:
如果没有安装打印机返回提示信息
function AddPaper(PaperName: PChar;fPaperWidth,fPaperHeigth:do
uble): String;
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode : THandle;
hPrinter: THandle;
FormInfo: TForminfo1;
PaperSize: TSize;
PaperRect: TRect;
PaperWidth,PaperHeigth: Integer;
function Zlxs(S: String;nWs: Integer): String;
begin
Try
Result:=FloatToStr(StrToFloat(S));
If pos('.',Result)>0 then
Result:=Copy(Result,1,pos('.',Result)+2);
Result:=FloatToStr(StrToFloat(Result)*10000);
Except
Result:='0';
end;
end;
begin
PaperWidth:=StrToInt(Zlxs(FloatToStr(fPaperWidth),3));
Paperheigth:=StrToInt(Zlxs(FloatToStr(fPaperheigth),3));
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter=0 then
begin
Result:='没有安装打印机!';
Exit;
end;
FormInfo.Flags:=FORM_USER;
FormInfo.pName:=PChar(PaperName);
PaperSize.cx:=PaperWidth;
PaperSize.cy:=PaperHeigth;
PaperRect.Left:=0;
PaperRect.Top:=0;
PaperRect.Right:=PaperSize.cx;
PaperRect.Bottom:=PaperSize.cy;
FormInfo.Size:=PaperSize;
FormInfo.ImageableArea:=PaperRect;
AddForm(hPrinter,1,@FormInfo);
ClosePrinter(hPrinter);
end;