Board index » delphi » printing graphics to a printer without a printer driver

printing graphics to a printer without a printer driver

Hi all

I am trying to print to a point-of-sale printer which has
no drivers for Windows NT.

I am trying to print Arabic characters to that printer.

Any suggestions?

Salim Naufal
salim.nau...@softnet-eng.com

-------------------------------------------------

 

Re:printing graphics to a printer without a printer driver


Quote
In article <7ti97q$m...@forums.borland.com>, Salim Naufal wrote:
> I am trying to print to a point-of-sale printer which has
> no drivers for Windows NT.

> I am trying to print Arabic characters to that printer.

How you approach this, and whether it is possible at all, depends
completely on the printers capabilities. You basically work on this
like you would under DOS: you compose a stream of bytes containing the
required printer commands and the image data in whatever format the
printer requires and send it to the printer using
WinSpool.WritePrinter, which bypasses the printer driver (install the
gerneric/text driver for this printer).

<quote>
Printing a file directly to a printer in Win32, code by Joe Hecht.

<suspend quote>
Joe posted a complete unit with useful routines some time ago, go to
http://www.dejanews.com, http://www.mers.com/searchsite.html, or
http://developers.href.com and search the newsgroups for PrintRawData.
<resume quote>

Note that you have to include WinSpool in the uses clause.

procedure PrintFile(const sFileName: string);
const
  BufSize = 16384;
type
  TDoc_Info_1 = record
    pDocName: pChar;
    pOutputFile: pChar;
    pDataType: pChar;
  end;
var
  Count, BytesWritten: integer;
  hPrinter: THandle;
  Device : array[0..255] of char;
  Driver : array[0..255] of char;
  Port   : array[0..255] of char;
  hDeviceMode: THandle;
  DocInfo: TDoc_Info_1;
  f: file;
  Buffer: Pointer;
begin
  Printer.PrinterIndex := -1;
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  if not WinSpool.OpenPrinter(@Device, hPrinter, nil) then exit;
  DocInfo.pDocName := 'MyDocument';
  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, sFileName);
  try
    Reset(f, 1);
    GetMem(Buffer, BufSize);
    while not eof(f) do
    begin
      Blockread(f, Buffer^, BufSize, Count);
      if Count > 0 then
      begin
        if not WritePrinter(hPrinter, Buffer, Count, BytesWritten) then
        begin
          EndPagePrinter(hPrinter);
          EndDocPrinter(hPrinter);
          WinSpool.ClosePrinter(hPrinter);
          FreeMem(Buffer, BufSize);
          exit;
        end;
      end;
    end;
    FreeMem(Buffer, BufSize);
    EndDocPrinter(hPrinter);
    WinSpool.ClosePrinter(hPrinter);
  finally
    System.Closefile( f );
  end;
end;

*************************************
 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 DocInfo do
   begin
   pDocName := PChar('test doc');
   pOutputFile := nil;
   pDataType := 'RAW';
   end;
 StartDocPrinter(Handle, 1, ocInfo);
 StartPagePrinter(Handle);
 WritePrinter(Handle, PChar(S), Length(S), N);
 EndPagePrinter(Handle);
 EndDocPrinter(Handle);
 ClosePrinter(Handle);
 end;

The PrinterName parameter must be the name of the printer as it is
installed. For example, if the name of the printer
is "HP LaserJet 5MP" then that is what you should pass.

</quote>

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads