用以下函数创建一个自定义纸张(对win98无效),然后纸张类型选择成formname就行了,别忘了use winspool
procedure PrnAddForm(const FormName: string;
PaperWidth, PaperLength:integer;const leftmargin:integer=0;const rightmargin:integer=0;const topmargin:integer=0;const bottommargin:integer=0);
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode : THandle;
hPrinter: THandle;
FormInfo: TFormInfo1;
PaperSize: TSize;
PaperRect: TRect;
errcode: integer;
s: string;
begin
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter = 0 then
raise Exception.Create('Failed to open printer!');
FormInfo.Flags := FORM_USER;
FormInfo.pName := PChar(FormName);
PaperSize.cx := PaperWidth*1000;
PaperSize.cy := PaperLength*1000;
PaperRect.Left := 0;
PaperRect.Top := 0;
PaperRect.Right := paperwidth*1000;
PaperRect.Bottom :=paperlength*1000;
paperrect.TopLeft.X :=leftmargin*1000;
paperrect.topleft.y:=topmargin*1000;
paperrect.BottomRight.X :=paperwidth*1000-rightmargin*1000;
paperrect.BottomRight.y:=paperlength*1000-bottommargin*1000;
FormInfo.Size := PaperSize;
FormInfo.ImageableArea := PaperRect;
if not AddForm(hPrinter, 1, @FormInfo) then
begin
errcode := GetLastError;
if errcode <> ERROR_FILE_EXISTS then
// Form name exists?
begin
case errcode of
ERROR_ACCESS_DENIED: s := '拒绝操作!';
ERROR_INVALID_HANDLE: s := '无郊的打印机!';
ERROR_NOT_READY: s := '打印机未准备好!';
ERROR_CALL_NOT_IMPLEMENTED:
s := '操作系统不支持此项添加自定义纸张的功能!';
else
s := 'Failed to add a Form (paper) name!';
end;
raise Exception.Create(s);
end;
end;
ClosePrinter(hPrinter);
end;