算了,送你一段函数吧
procedure printPage(
const formName: string;
const formWidth, formLength:integer);
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode :THandle;
hPrinter :THandle;
FormInfo :TFormInfo1;
PaperSize:TSize;
PaperRect:TRect;
begin
{Win2K/XP/2003下添加打印纸张,单位:0.1毫米}
try
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter = 0 then
raise Exception.Create('打开打印机失败!');
try
{删除纸张格式----------------------------------------------------------------}
if(formWidth = 0)
or(formLength= 0) then
begin
DeleteForm(hPrinter, PChar(formName));
exit;
end;
{增加纸张格式----------------------------------------------------------------}
FormInfo.Flags := FORM_USER;
FormInfo.pName := PChar(FormName);
PaperSize.cx := formWidth *100;
PaperSize.cy := formLength*100;
PaperRect.Left := 0;
PaperRect.Top := 0;
PaperRect.Right := PaperSize.cx;
PaperRect.Bottom := PaperSize.cy;
FormInfo.Size := PaperSize;
FormInfo.ImageableArea := PaperRect;
if SetForm(hPrinter, PChar(FormName), 1, @FormInfo) then
exit;{纸张存在}
if AddForm(hPrinter, 1, @FormInfo) then
exit;
{添加成功}
// case GetLastError of
// ERROR_FILE_EXISTS: strTemp := '纸张格式已经存在!';
// Form name exists?
// ERROR_ACCESS_DENIED: strTemp := '存取失败!';
// ERROR_INVALID_HANDLE: strTemp := '无效句柄';
// ERROR_NOT_READY: strTemp := '设备没有准备!';
// ERROR_CALL_NOT_IMPLEMENTED: strTemp := '系统不支持!';
// else
strTemp := '增加纸张格式失败!';
// end;
// raise Exception.Create(strTemp);
finally
ClosePrinter(hPrinter);
end;
except
end;
end;
调用 printPage('Custom', 23000, 14000);{WinNT下添加自定义打印页格式}