Sunday, 15 August 2010

Delphi printing to Generic text driver (Intermec PM4i)? -



Delphi printing to Generic text driver (Intermec PM4i)? -

(edit question has received few downvotes. don't know reason , still cannot see what's wrong it. can edit if downvoters comment wish see improve written or lack of valuable info have not given).

i have intermec pm4i label printer , generic text print driver. able print text file script notepad or delphi calls shellexecute('printto',..) shellapi function.

i found few raw printing examples none work. how can delphi app print generic_text_driver without shellapi function? not gdi printer.canvas capable driver.

i have tried "everything" legacy passthrough printing examples. working method notepad.exe or shellexecute('printto', 'tempfile.txt',...) guess using notepad internally. can see notepad printing dialog flashing on screen. command straight delphi application.

this printfiletogeneric did not work.

// https://groups.google.com/forum/#!topic/borland.public.delphi.winapi/vihjstf5eqa procedure printfiletogeneric(const sfilename, printername, docname: string; ejectpage: boolean); const bufsize = 16384; var count : integer; byteswritten: dword; hprinter: thandle; docinfo: tdocinfo1; f: file; buffer: pointer; ch: char; begin if not winspool.openprinter(pchar(printername), hprinter, nil) raise exception.create('printer not found'); seek docinfo.pdocname := pchar(docname); docinfo.poutputfile := nil; docinfo.pdatatype := 'raw'; if startdocprinter(hprinter, 1, @docinfo) = 0 raise exception.create('startdocprinter failed'); seek if not startpageprinter(hprinter) raise exception.create('startpageprinter failed'); system.assign(f, sfilename); seek reset(f, 1); getmem(buffer, bufsize); seek while not eof(f) begin blockread(f, buffer^, bufsize, count); if count > 0 begin if not writeprinter(hprinter, buffer, count, byteswritten) raise exception.create('writeprinter failed'); end; end; if ejectpage begin ch:= #12; writeprinter( hprinter, @ch, 1, byteswritten ); end; freemem(buffer, bufsize); end; endpageprinter(hprinter); system.closefile( f ); end; enddocprinter(hprinter); end; winspool.closeprinter(hprinter); end; end;

the next prtraw helper util illustration did not work.

prtraw.startrawprintjob/startrawprintpage/printrawdata/endrawprintpage/endrawprintjob http://www.swissdelphicenter.ch/torry/showcode.php?id=940

the next assignprn method did not work.

function testprinttext(params: tstrings): integer; var stemp:string; idx: integer; poutput: textfile; begin result:=0; idx := getprinterindexbyname( params.values['printer'] ); if (idx<0) raise exception.create('printer not found'); writeln('use printer(text) ' + inttostr(idx) + ' ' + printer.printers[idx] ); printer.printerindex := idx; stemp := params.values['jobname']; if (stemp='') stemp:='rawtextprint'; printer.title:=stemp; assignprn(poutput); rewrite(poutput); stemp := 'input on'+#10; stemp := stemp + 'nasc 1252'+#10; stemp := stemp + 'bf off'+#10; stemp := stemp + 'pp 30,480:ft "swiss 721 bt",8,0,100'+#10; stemp := stemp + 'pt "test text 30,480 position abc'+#10; write(poutput, stemp); //write(poutput, 'input on:'); //write(poutput, 'nasc 1252:'); //write(poutput, 'bf off:'); //write(poutput, 'pp 30,480:ft "swiss 721 bt",8,0,100:'); //write(poutput, 'pt "test text 30,480 position abc":'); //write(poutput, 'text line 3 goes here#13#10'); //write(poutput, 'text line 4 goes here#13#10'); closefile(poutput); end;

this printer.canvas did not print anything, should have had print because notepad internally using gdi printout. missing here.

function testprintgdi(params: tstrings): integer; var filename, docname:string; idx: integer; lines: tstrings; begin result:=0; idx := getprinterindexbyname( params.values['printer'] ); if (idx<0) raise exception.create('printer not found'); writeln('use printer(gdi) ' + inttostr(idx) + ' ' + printer.printers[idx] ); docname := params.values['jobname']; if (docname='') docname:='rawtextprint'; filename := params.values['input']; if not fileexists(filename) raise exception.create('input file not found'); printer.printerindex := idx; printer.title := docname; printer.begindoc; lines := readtextlines(filename); seek idx := 0 lines.count-1 begin printer.canvas.textout(10, 10*idx, lines[idx]); end; freeandnil(lines); printer.enddoc; end; end;

only 3 methods working printing notepad.exe, delphi shellexecute phone call or open raw tcp socket ip:port address , write text lines socket outputstream.

function testprintprintto(params: tstrings): integer; var filename, printername:string; idx: integer; exinfo: tshellexecuteinfo; device,driver,port: array[0..255] of char; hdevicemode: thandle; timeout:integer; //iret: cardinal; begin result:=0; idx := getprinterindexbyname( params.values['printer'] ); if (idx<0) raise exception.create('printer not found'); writeln('use printer(printto) ' + inttostr(idx) + ' ' + printer.printers[idx] ); filename := params.values['input']; if not fileexists(filename) raise exception.create('input file not found'); filename := ucommon.absolutefilepath(filename); printer.printerindex := idx; printer.getprinter(device, driver, port, hdevicemode); printername := format('"%s" "%s" "%s"', [device, driver, port]); fillchar(exinfo, sizeof(exinfo), 0); exinfo begin cbsize := sizeof(exinfo); fmask := see_mask_nocloseprocess or see_mask_flag_ddewait; wnd := 0; exinfo.lpverb := 'printto'; exinfo.lpparameters := pchar(printername); lpfile := pchar(filename); lpdirectory := nil; nshow := sw_hide; end; writeln('printto ' + printername); if not shellexecuteex(@exinfo) begin raise exception.create('shellexecuteex failed'); exit; end; seek timeout := 30000; while waitforsingleobject(exinfo.hprocess, 50) <> wait_object_0 begin writeln('wait timeout ' + inttostr(timeout)); dec(timeout, 50); if (timeout<1) break; end; closehandle(exinfo.hprocess); end; {iret:=shellexecute(0, 'printto', pchar(filename), pchar(printername), //printer.printers[idx]), nil, //pchar(filepath), sw_hide // sw_shownormal ); writeln('printto homecoming code ' + inttostr(iret)); // >32 ok } end;

you able print printer notepad. notepad prints using standard gdi mechanism. if notepad can can you. utilize printer.begindoc, printer.canvas etc. print printer.

delphi printing intermec

No comments:

Post a Comment