delphi - print a string directly to printer -


i need print string directly printer
found code searching

uses winspool, printers  type   tdoc_info_1 = record     pdocname: pchar;     poutputfile: pchar;     pdatatype: pchar;   end;   procedure printsimpletext(sprinter, stext: string); var   stitle: string;   hprinter: thandle;   prndocinfo: tdoc_info_1;   lst: tstringlist;   i: integer;   n: cardinal;   stextline: string;   bfound: boolean; begin   lst := tstringlist.create;   try     lst.text := stext; //with crlf     //new doc     stitle := 'raw print';     zeromemory(@prndocinfo, sizeof(tdoc_info_1));     prndocinfo.pdocname := pchar(stitle);     prndocinfo.pdatatype := 'raw';     //find printer (if installed in windows)     bfound := false;     i:=1 printer.printers.count     begin       if pos(sprinter, printer.printers.strings[i-1])>0       begin         bfound := true;         sprinter := printer.printers.strings[i-1];         printer.printerindex := i-1; //set printer         break;       end;     end;      if bfound     begin       // open printer       if openprinter(pchar(sprinter), hprinter, nil)       begin         //start         startdocprinter(hprinter, 1, @prndocinfo);         if startpageprinter(hprinter)         begin           //print line           := 1 lst.count           begin             stextline := lst.strings[i-1];             if not writeprinter(hprinter, pchar(stextline), length(stextline), n)               break;           end;           //end of page           endpageprinter(hprinter);           //end           enddocprinter(hprinter);         end;         closeprinter(hprinter);       end;     end;       lst.free;   end; end; 

and run :

procedure tform1.button1click(sender: tobject); begin   printsimpletext('pdffactory pro', 'tis a'#13#10'text');   showmessage('aaaa'); end; 

1) clicking button1 show message!!! required send custom header string print? or problem here?

2) if think not way tell me better solution! need submit string printer

------------------------------------------------------       card number 1111 1111 1111 1111            name mr xxxx xxxxxxx         nationality code 9999999999 ------------------------------------------------------               password : 555555 ----------------------------------------------------- 

at first tried save string text file , send pronter printer printed file name @ top of file

then tried create bitmap image , send machine printer dot matrix , don't understand image!!

update:

this code work on pc think printer detected , working fine.

procedure tform1.button2click(sender: tobject); begin if opendialog1.execute shellexecute(handle, 'print', pchar(opendialog1.filename), nil, nil, sw_hide) ; end; 

this can job too

  printer.begindoc;   printer.canvas.textout(0,0,'place text here');   printer.enddoc; 

also canvas can edit styling too

   printer.canvas.font.size:=18;    printer.canvas.font.style := [fsbold]; 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -