Domanda

I have written a function that prints out ZPLII data to a Zebra printer as shown below

var
  St : string;

StartDocument(DocName);
StartPage;
Try
For I:=0 to DataToPrint.Count-1 do
 Begin
  St:=FormatPrintLine(I);
   Try
    Escape(PrinterHandle,PASSTHROUGH,Length(St),PAnsiChar(St),Nil);
   Except on E:Exception do
    begin
      GetWin32ApiErrorMessage(FErrorCode,FErrorText);
      Raise EPrinter.CreateFmt('Printer Write Error %d'+#13+
                               'While Printing To '+PrinterName+#13+
                               ErrorText,[ErrorCode]);
     end;
   End;
 end;
Finally
 EndPage;
 EndDocument;

I have tested the label data by using the command prompt to print it from a text file and the label prints out correctly but i cannot print it from my application. If i pause the printer i can see the job gets sent to the printer and the size of the job is 2.12Kb, roughly the size the label should be, but nothing prints out. The light on the Zebra printer for data lights up but nothing will print. I have tried this with two of the Zebra printers we own, so it is not a printer issue. My guess at this point is that maybe the program isn't sending the entire label data to the printer and the end is never received but when i trace through the send request, everthing is sent properly. the printer also shows the job has 0/0 pages for the label but i cannot understand why it is not sending the label. Is there something special that needs to go at the end of the label data besides the ^XZ termination character? I am also using Delphi XE3 if that helps.

È stato utile?

Soluzione

Thanks to everyone's help I was able to successfully print my labels using the following changes:

St: AnsiString;
...
StartDocument(DocName);
StartPage;
Try
 For I:=0 to DataToPrint.Count-1 do
  Begin
   St:=FormatPrintLine(I);
    Try
     WritePrinter(PrinterHandle,PChar(St),Length(St),N);
    Except on E:Exception do
     begin
       GetWin32ApiErrorMessage(FErrorCode,FErrorText);
       Raise EPrinter.CreateFmt('Printer Write Error %d'+#13+
                               'While Printing To '+PrinterName+#13+
                               ErrorText,[ErrorCode]);
      end;
    End;
  end;
Finally
 EndPage;
 EndDocument;

I also had to change to writeprinter instead of escape. Escape did not print anything out after i change st to type AnsiString but writeprinter was successful.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top