//-------------------------------------------------------------------------
// Copyright (c) 2003 - PW&T <info@ipworks.de>
// All Rights Reserved
// web: [url]http://www.ipworks.de[/url]
//-------------------------------------------------------------------------
unit spoolps;
interface
uses
Forms,SysUtils,Graphics,Classes,CtlPanel,Windows,Printers,WinSpool;
procedure PrintPSFile(
Const sFileName: PChar; PrIndex:Integer);
function IsPostScriptPrinter(
dc : hdc) : integer;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
implementation
function IsPostScriptPrinter(
dc : hdc) : integer;
//Feststellung ob Drucker PS-Drucker
var
TestInt : integer;
a :
array[0..255]
of char;
err : integer;
s :
string;
begin
Result := 1;
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 := 0;
end;
end;
end;
procedure PrintPSFile(
Const sFileName: PChar; PrIndex:Integer);
{ Prints a text file directly to the default printer. }
Const
cBUFSIZE = 16384;
Type
TDoc_Info_1 =
record
pDocName: pChar;
pOutputFile: pChar;
pDataType: pChar;
end;
Var
// Count,
// BytesWritten: Integer; { Delphi 1, 2, 3 }
Count : Cardinal;
BytesWritten: Cardinal;
hPrinter : THandle;
hDeviceMode : THandle;
Device :
Array[0..255]
Of Char;
Driver :
Array[0..255]
Of Char;
Port :
Array[0..255]
Of Char;
DocInfo : TDoc_Info_1;
f :
File;
Buffer : Pointer;
begin
Printer.PrinterIndex := PrIndex;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
If Not WinSpool.OpenPrinter(@Device, hPrinter,
Nil)
Then Exit;
DocInfo.pDocName := sfilename;
DocInfo.pOutputFile :=
Nil;
DocInfo.pDatatype := '
RAW';
If StartDocPrinter(hPrinter, 1, @DocInfo) = 0
Then
begin
WinSpool.ClosePrinter(hPrinter);
Exit;
end;
If Not StartPagePrinter(hPrinter)
Then
begin
EndDocPrinter(hPrinter);
WinSpool.ClosePrinter(hPrinter);
Exit;
end;
System.Assign(f,
string(sFileName));
try
Reset(f, 1);
GetMem(Buffer, cBUFSIZE);
While Not Eof(f)
Do
begin
Blockread(f, Buffer^, cBUFSIZE, Count);
If Count > 0
Then
begin
If Not WritePrinter(hPrinter, Buffer, Count, BytesWritten)
Then
begin
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
WinSpool.ClosePrinter(hPrinter);
FreeMem(Buffer, cBUFSIZE);
Exit;
end;
end;
end;
FreeMem(Buffer, cBUFSIZE);
EndDocPrinter(hPrinter);
WinSpool.ClosePrinter(hPrinter);
finally
System.CloseFile(f);
end;
end;
end.