Author: Peter Below
How to check if a printer supports postscript?
Answer:
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!):
1 uses2 WinSpool, Printers;
3 4 {: Check if the currently selected printer supports postscript.5 Only applicable on Win2K/XP! }6 7 function PrinterSupportsPostscript: Boolean;
8 const9 POSTSCRIPT_PASSTHROUGH = 4115;
10 POSTSCRIPT_IDENTIFY = 4117;
11 12 Escapes: array[0..2] of Cardinal =
13 (POSTSCRIPT_DATA, POSTSCRIPT_IDENTIFY, POSTSCRIPT_PASSTHROUGH);
14 var15 res: Integer;
16 i: Integer;
17 begin18 Result := false;
19 for i := Low(Escapes) to High(Escapes) do20 begin21 res := ExtEscape(printer.Handle,
22 QUERYESCSUPPORT,
23 sizeof(Escapes[0]),
24 @Escapes[i], 0, nil);
25 if res <> 0 then26 begin27 Result := true;
28 Break;
29 end;
30 end;
31 end;
32 33 procedure TForm1.Button1Click(Sender: TObject);
34 const35 boolstr: array[Boolean] ofstring = (' not', '');
36 var37 i: Integer;
38 S: string;
39 begin40 for i := 0 to Printer.Printers.Count - 1 do41 begin42 Printer.PrinterIndex := i;
43 memo1.Lines.add(
44 Format('Printer %s does%s support Postscript',
45 [printer.printers[printer.printerindex],
46 boolstr[PrinterSupportsPostscript]]));
47 end;
48 end;