首页  编辑  

检查打印机是否支持PostScript

Tags: /超级猛料/Print.打印/   Date Created:

检查打印机是否支持PostScript

Check if a printer supports postscript?

{

 That is really difficult do to if it has to work on all Windows

 platforms. The best way (no kidding) may be to ask the user which

 printer to use. What platforms do you need to support? If it is only

 Win2K (and perhaps XP) one may be able to use this (i have no

 postscript-enabled printer around to see if it works!):

}

uses

 WinSpool, Printers;

{: Check if the currently selected printer supports postscript.

 Only applicable on Win2K/XP! }

function PrinterSupportsPostscript: Boolean;

const

 POSTSCRIPT_PASSTHROUGH = 4115;

 POSTSCRIPT_IDENTIFY = 4117;

 Escapes: array[0..2] of Cardinal =

 (POSTSCRIPT_DATA, POSTSCRIPT_IDENTIFY, POSTSCRIPT_PASSTHROUGH);

var

 res: Integer;

 i: Integer;

begin

 Result := false;

 for i := Low(Escapes) to High(Escapes) do begin

   res := ExtEscape(printer.Handle,

     QUERYESCSUPPORT,

     sizeof(Escapes[0]),

     @Escapes[i], 0, nil);

   if res <> 0 then begin

     Result := true;

     Break;

   end;

 end;

end;

procedure TForm1.Button1Click(Sender: TObject);

const

 boolstr: array[Boolean] of string = (' not', '');

var

 i: Integer;

 S: string;

begin

 for i := 0 to Printer.Printers.Count - 1 do begin

   Printer.PrinterIndex := i;

   memo1.Lines.add(

     Format('Printer %s does%s support Postscript',

     [printer.printers[printer.printerindex],

     boolstr[PrinterSupportsPostscript]]));

 end;

end;

---------------------------------------

判断打印机能否打印PostScript

uses Printers;

function IsPostScriptPrinter(dc : hdc) : bool;

var

TestInt : integer;

a : array[0..255] of char;

err : integer;

s : string;

begin

Result := false;

TestInt := GETTECHNOLOGY;

{$IFDEF WIN32}

if ExtEscape(Dc,

QUERYESCSUPPORT,

sizeof(TestInt),

@TestInt,

0,

Nil) > 0 then begin

Err := ExtEscape(Dc,

GETTECHNOLOGY,

0,

nil,

256,

@a);

{$ELSE}

if Escape(Dc,

QUERYESCSUPPORT,

sizeof(TestInt),

@TestInt,

Nil) > 0 then begin

Err := Escape(Dc,

GetTechnology,

0,

nil,

@a);

{$ENDIF}

if Err > 0 then begin

s := UpperCase(StrPas(a));

if Pos('POSTSCRIPT', s) > 0 then

result := true;

end;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

if PrintDialog1.Execute then

if IsPostScriptPrinter(Printer.Handle) then

ShowMessage('This is a Postscript Printer') else

ShowMessage('This is not a Postscript Printer');

end;