procedure PaperSizeSet(iaWith,iaLength:Integer);
var
ADevice : array[0..255] of char;
ADriver : array[0..255] of char;
APort : array[0..255] of char;
hDevHandle : THandle;
PDevMode : PDeviceMode;
//A Pointer to a TDeviceMode structure
begin
Printer.PrinterIndex:=Printer.PrinterIndex;
// GetPrinter() 首先获得TPrinter的DeviceMode结构的句柄
Printer.GetPrinter(ADevice, ADriver, APort, hDevHandle);
//如果句柄为0,表示打印机没有装载
if hDevHandle = 0 then
begin
Printer.PrinterIndex:=Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, hDevHandle);
end;
//如果句柄还是为0,表示有错误发生。否则,就调用
if hDevHandle = 0 then
raise Exception.Create('不能初始化打印结构,请察看打印机是否已加载')
else
if hDevHandle<>0 then
begin
PDevMode:=GlobalLock(hDevHandle);//GlobalLock()获取TDeviceMode结构的指针
if PDevMode <> nil then
try
//Set to legal
PDevMode^.dmFields := PDevMode^.dmFields or dm_PaperSize;
PDevMode^.dmPaperSize := DMPAPER_LEGAL;
//Set to custom size //设置定制的大小
PDevMode^.dmFields := PDevMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH ;
PDevMode^.dmPaperSize :=DMPAPER_USER;
PDevMode^.dmPaperWidth :=iaWith;
//SomeValueIn Tenths Of A Millimeter;
PDevMode^.dmPaperLength :=iaLength;
//SomeValueInTenthsOfAMillimeter;
{ //Set the bin to use
PDevMode^.dmFields := PDevMode^.dmFields or DMBIN_MANUAL;
PDevMode^.dmDefaultSource := DMBIN_MANUAL;
}
finally
GlobalUnlock(hDevHandle);
end;
end
else
raise Exception.Create('不能设置打印纸张大小');
Printer.PrinterIndex := Printer.PrinterIndex;
end;
这样就行啦,它可以任意的设置纸张的大小拉,呵呵,我的嵌套打印全靠它的