Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-07

USB Printers

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roberto Gonçalves Barreiro

I'm a delphi programmer.
I'm printing a report using:
assign(wPrinter,'Lpt1:')
and it goes ok in paralel priner.
I did assign(wPrinter,'USB001') and it did not work. Do you know how to print in USB printers?
I thanks a lot if you can help me.

Roberto Barreiro
Recife, Brazil

Roberto Barreiro, Recife, PE, Brasil - Fone: (81) 9932-0550

---------------------------------
Novo Yahoo! Cadê? - Experimente uma nova busca.

Reply by email

Tom York
to Roberto Gonçalves Barreiro

Since you specify LPT1:, I assume you are using Windows. Obviously the solution for Linux would be different than Windows. I am not quite sure about FPC, but in Delphi you basically have two choices.

1) Capture the USB printer to an LPT port, then attempt assign(printer, 'LPTx:'); (not a good solution in my opinion).

2) Open the Windows printer in RAW mode. I've used this style of printing to a Eltron USB thermal printer and it worked well. The procedure below is quite similar to the one I used.

Please write back and let me know if this routine works.

(Begin Procedure -- From Delphi newsgroups)
uses WinSpool;
procedure WriteRawStringToPrinter(PrinterName: String; S: String);
 var
   Handle: THandle;
   N: DWORD;
   DocInfo1: TDocInfo1;
 begin
   if not OpenPrinter(PChar(PrinterName), Handle, nil) then
     begin
      ShowMessage('error ' + IntToStr(GetLastError));
      Exit;
     end;
   with DocInfo1 do begin
     pDocName := PChar('test doc');
     pOutputFile := nil;
     pDataType := 'RAW';
   end;
   StartDocPrinter(Handle, 1, @DocInfo1);
   StartPagePrinter(Handle);
   WritePrinter(Handle, PChar(S), Length(S), N);
   EndPagePrinter(Handle);
   EndDocPrinter(Handle);
   ClosePrinter(Handle);
 end;
(End Procedure)

Tom

Roberto Gonçalves Barreiro wrote 8 lines
I'm a delphi programmer. I'm printing a report using: assign(wPrinter,'Lpt1:') and it goes ok in paralel priner. I did assign(wPrinter,'USB001') and it did not work. Do you know how to print in USB printers? I thanks a lot if you can help me.

Reply by email

Tom York
to Tom York: Since you specify LPT1:, I assume you are using Windows. Obviously the solution for…

Disregard my prior post, it is Delphi specific. I did find this one.

(http://www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/components/printers/samples/rawmode/unitmain.pas?root=lazarus&rev=10129&view=markup)

procedure WritePrinter;
var
  sTemp: String;
  Written: Integer;
begin
  Written := 0;
  sTemp := 'Test String';
  Printer.Title := Caption;
  Printer.RawMode := True;
  Printer.BeginDoc;
  Printer.Write(sTemp[1], Length(sTemp), Written);
  Printer.EndDoc;
end;

Reply by email