Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2012, 04:10 PM
lgastmans lgastmans is offline
Junior Member
 
Join Date: Apr 2012
Posts: 1
Default print to USB port

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?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 05:36 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.