Delphi printing in Generic text driver (Intermec PM4i)?

( edit ). This question received several downvotes. I do not know the reason and still do not see what is wrong with him. I can edit this if downvoters can comment that they want to see better written or lack of valuable information that I did not give).

I have an Intermec PM4i label printer and a universal text print driver. I can print a text file script from Notepad or Delphi calls ShellExecute ('printto', ..) shellapi.

I found some examples of raw printing, but no one is working. How can a Delphi application print in Generic_text_driver without shellapi function? This is not a GDI printer.canvas driver.

I tried "everything" even on previous PASSTHROUGH printing examples. Only the working method of Notepad.exe or shellexecute ('printto', 'tempfile.txt', ...), which I assume uses Notepad internally. I see that on the screen a dialog box blinking with writing to a notebook flashes. I would like to control this directly from the Delphi application.

This printFileToGeneric file does 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) Then raise Exception.Create('Printer not found'); Try DocInfo.pDocName := PChar(docName); DocInfo.pOutputFile := nil; DocInfo.pDatatype := 'RAW'; If StartDocPrinter(hPrinter, 1, @DocInfo) = 0 Then Raise Exception.Create('StartDocPrinter failed'); Try If not StartPagePrinter(hPrinter) Then Raise Exception.Create('StartPagePrinter failed'); System.Assign(f, sFileName); Try Reset(f, 1); GetMem(Buffer, BufSize); Try While not eof(f) Do Begin Blockread(f, Buffer^, BufSize, Count); If Count > 0 Then Begin If not WritePrinter(hPrinter, Buffer, Count, BytesWritten) Then Raise Exception.Create('WritePrinter failed'); End; End; Finally If ejectPage Then Begin ch:= #12; WritePrinter( hPrinter, @ch, 1, BytesWritten ); End; FreeMem(Buffer, BufSize); End; Finally EndPagePrinter(hPrinter); System.Closefile( f ); End; Finally EndDocPrinter(hPrinter); End; Finally WinSpool.ClosePrinter(hPrinter); End; End; 

The following prtRaw utility example does not work.

 prtRaw.StartRawPrintJob/StartRawPrintPage/PrintRawData/EndRawPrintPage/EndRawPrintJob http://www.swissdelphicenter.ch/torry/showcode.php?id=940 

The following AssignPrn method does 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) then Raise Exception.Create('Printer not found'); WriteLn('Use printer(text) ' + IntToStr(idx) + ' ' + Printer.Printers[idx] ); Printer.PrinterIndex := idx; stemp := params.Values['jobname']; if (stemp='') then 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 didn't print anything, it had to print something because Notepad internally uses the GDI printout. Something is 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) then Raise Exception.Create('Printer not found'); WriteLn('Use printer(gdi) ' + IntToStr(idx) + ' ' + Printer.Printers[idx] ); docName := params.Values['jobname']; if (docName='') then docName:='rawtextprint'; filename := params.values['input']; If Not FileExists(filename) then Raise Exception.Create('input file not found'); Printer.PrinterIndex := idx; Printer.Title := docName; Printer.BeginDoc; lines := readTextLines(filename); try for idx := 0 to lines.Count-1 do begin Printer.Canvas.TextOut(10, 10*idx, lines[idx]); end; finally FreeAndNil(lines); Printer.EndDoc; end; end; 

Only three working methods are printing from Notepad.exe, calling Delphi ShellExecute or opening a raw TCP socket to IP: PORT address and writing text strings to the socket output stream.

 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) then Raise Exception.Create('Printer not found'); WriteLn('Use printer(printto) ' + IntToStr(idx) + ' ' + Printer.Printers[idx] ); filename := params.values['input']; If Not FileExists(filename) then 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); with exInfo do 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) then begin Raise Exception.Create('ShellExecuteEx failed'); exit; end; try timeout := 30000; while WaitForSingleObject(exInfo.hProcess, 50) <> WAIT_OBJECT_0 do begin Writeln('wait timeout ' + IntToStr(timeout)); dec(timeout, 50); if (timeout<1) then break; end; finally CloseHandle(exInfo.hProcess); end; {iRet:=ShellExecute(0, 'printto', PChar(filename), PChar(printerName), //Printer.Printers[idx]), nil, //PChar(filepath), SW_HIDE // SW_SHOWNORMAL ); Writeln('printto return code ' + IntToStr(iRet)); // >32 OK } end; 
0
source share
2 answers

You can print on this printer from Notepad. Notepad prints using the standard GDI mechanism. If Notepad can do this, then you can too. Use Printer.BeginDoc , Printer.Canvas , etc. For printing on this printer.

0
source

you can use this procedure: where LabelFile is the full path to the label file, we use this code and work with a universal text driver printer, and the printer is installed as the default printer. It works with a zebra printer and Windows XP operating system.

Hope this helps you.

 function PrintLabel(LabelName: String): Boolean; var EfsLabel,dummy: TextFile; ch : Char; begin try try Result:= False; AssignFile(EfsLabel,LabelName); Reset(EfsLabel); Assignprn(dummy); ReWrite(Dummy); While not Eof(EfsLabel) do begin Read(EfsLabel, Ch); Write(dummy, Ch); end; Result:= True; except Result:=False; LogMessage('Error Printing Label',[],LOG_ERROR); end; finally CloseFile(EfsLabel); CloseFile(dummy); end; end; 
0
source

Source: https://habr.com/ru/post/1500430/


All Articles