I'm trying to send a print command to Zebra using EPL:
For Windows I use the following command:
Type test.txt > "\\desktop-AB123\ZDesigner ZD230-203dpi ZPL"
test.txt
N
R30,10
D10
A210,0,0,1,1,1,N,"MATHEUS"
B285,65,0,1,2,1,70,N,"s"
A210,20,0,1,1,1,N,"210"
A210,35,0,1,1,1,N,"12000"
A330,35,0,1,1,1,N,"12"
A210,50,0,1,1,1,N,"V"
A430,50,0,1,1,1,N,"DN"
A195,220,3,1,1,1,R," TEST"
A210,143,0,1,1,1,N,"TEST"
A210,158,0,1,1,1,N,"TEST"
A210,173,0,1,1,1,N,"TEST"
A450,173,0,1,1,1,N,"TEST"
A210,188,0,1,1,1,N,"H"
A210,206,0,1,1,1,N,""
P1
N
It works perfectly using the same text file in the Zebra Utilities sendFile
or in Windows printers.
I tried to do it the following way in Delphi 7:
procedure PrintFileWithCommand(const FileName, PrinterName: string);
var
Command: string;
begin
Command := 'cmd /C type "' + FileName + '" > "' + PrinterName + '"';
WinExec(PChar(Command), SW_HIDE);
end;
procedure SendRawDataToPrinter(const PrinterName: string; const RawData: string);
var
hPrinter: THandle;
DocInfo: TDocInfo1;
BytesWritten: DWORD;
PData: PAnsiChar;
begin
if not OpenPrinter(PChar(PrinterName), hPrinter, nil) then
raise Exception.Create('Error opening printer: ' + PrinterName);
try
FillChar(DocInfo, SizeOf(DocInfo), 0);
DocInfo.pDocName := 'EPL Command';
DocInfo.pOutputFile := nil;
DocInfo.pDatatype := 'RAW';
if StartDocPrinter(hPrinter, 1, @DocInfo) = 0 then
raise Exception.Create('Error starting document on printer.');
if not StartPagePrinter(hPrinter) then
raise Exception.Create('Error starting page on printer.');
PData := PAnsiChar(RawData);
if not WritePrinter(hPrinter, PData, Length(RawData), BytesWritten) then
raise Exception.Create('Error sending data to printer.');
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
finally
ClosePrinter(hPrinter);
end;
end;
procedure PrintFile(const FileName: string; PrinterIndex: Integer);
var
F: TextFile;
EPLContent: TStringList;
I: Integer;
begin
if not FileExists(FileName) then
begin
MessageBox(Application.Handle, 'Not found !', PChar('AT!'), MB_OK + MB_ICONWARNING);
Exit;
end;
EPLContent := TStringList.Create;
try
EPLContent.LoadFromFile(FileName);
Printer.PrinterIndex := PrinterIndex;
AssignPrn(F);
ReWrite(F);
try
for I := 0 to EPLContent.Count - 1 do
WriteLn(F, EPLContent[I]);
finally
CloseFile(F);
end;
MessageBox(Application.Handle, 'Sucess !', PChar('AT!'), MB_OK + MB_ICONWARNING);
except
on E: Exception do
ShowMessage('error: ' + E.Message);
end;
FreeAndNil(EPLContent);
end;
I tried using a .prn
:
ShellExecute(Handle, 'open', PChar('cmd.exe'), PChar('/c type ' + file+ ' > ' + imp), nil, SW_HIDE);
But without success either.
Some commands are sent to the printer spool but it does not print. But if I send the same text via sendFile
(Zebra Utilities or SendFile
printer properties), it works normally.
Does anyone have any idea what it could be?
Only the space and special characters removed from the printer share made the command operate accordingly (copy), sending a txt.