////////////////////////////
// 武漢探索電腦工作室 //
//
http://tansuo.51.Net // ////////////////////////////
//增加規格自定義紙張
//PaperName: 自定義紙張名稱
//PaperWidth: 紙張的寬度,以0.1mm為單位
//PaperLength: 紙張的高度,以0.1mm為單位
procedure TDM.AddCustomPaper(const PaperName: string; PaperWidth, PaperLength:integer);
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode : THandle;
hPrinter : THandle;
FormInfo : TFormInfo1;
begin
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter = 0 then
raise Exception.Create('聯接打印機失敗!');
with FormInfo do
begin
Flags := FORM_USER;
pName := PChar(PaperName);
Size.cx := PaperWidth*100;
Size.cy := PaperLength*100;
ImageableArea.Left := 0;
ImageableArea.Top := 0;
ImageableArea.Right := PaperWidth*100;
ImageableArea.Bottom := PaperLength*100;
end;
//修改紙型,如果沒有就新增
if not SetForm(hPrinter, PChar(PaperName), 1, @FormInfo) then
AddForm(hPrinter, 1, @FormInfo);
ClosePrinter(hPrinter);
end;
//刪除自定義規格紙張
//PaperName: 自定義紙張名稱
procedure TDM.DeleteCustomPaper(const PaperName: string);
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode : THandle;
hPrinter : THandle;
begin
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter = 0 then
raise Exception.Create('聯接打印機失敗!');
DeleteForm(hPrinter, PChar(PaperName));
ClosePrinter(hPrinter);
end;