The following code has worked for years with dot matrix printers connected via LPT ports, to print text files in draft mode. Now, these printers come with USB cables, LPT ports have dissappeared from motherboards, and I am stuck with a software that does not print anymore...
This is the function that prints a text file, which works with LPT ports:
Code:
procedure PrintTextFile(AFile: string);
var
APrinter, Str : string;
PDefs: PPrinterDefaults;
PrinterHandle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
FFile: TextFile;
begin
APrinter := GetPrinterName;
New(PDefs);
PDefs.pDatatype := nil;
PDefs.pDevMode := nil;
PDefs.DesiredAccess := PRINTER_ACCESS_USE;
AssignFile(FFile, AFile);
Reset(FFile);
try
if not OpenPrinter(PChar(APrinter), PrinterHandle, PDefs) then
MessageDlg('OpenPrinter Error: ' + IntToStr(GetLastError), mtError, [mbOk], 0)
else
begin
with DocInfo1 do
begin
pDocName := PChar(AFile);
pOutputFile := nil;
pDataType := 'RAW';
end;
StartDocPrinter(PrinterHandle, 1, @DocInfo1);
StartPagePrinter(PrinterHandle);
while not Eof(FFile) do
begin
Readln(FFile, Str);
WritePrinter(PrinterHandle, PChar(Str), Length(Str), N);
WritePrinter(PrinterHandle, PChar(#10#13), 2, N);
end;
EndPagePrinter(PrinterHandle);
EndDocPrinter(PrinterHandle);
ClosePrinter(PrinterHandle);
end;
finally
CloseFile(FFile);
Dispose(PDefs);
end;
end;
someone suggested to go to the properties of the printer, to the "ports" tab, and check "Enabled printer spooling" and to also check the LPT checkbox. But this does not do the job though.
Anyone with the same issue?