Hello,

I'm sending EPL code to a zebra printer. Printing one ticket works fine, but If I print a list of tickets it spits out too much paper after ticket 4 and misaligns the rest!

I've looked at and changed my code so many times but I cant see the problem. Has anyone any experience with sending EPL code?

I've tried sending it all as one print document and as individual documents.

Thankyou.



(there might be some erroneous variables below that are used for my EPL code)

Code:
procedure TPrintorExcelFRM.Button8Click(Sender: TObject);
var ADevice, ADeviceName, ADevicePort: array[0..255]of Char;
PrinterHandle: THandle;
DocInfo: TDocInfo1;
dwJob: cardinal;
dwBytesWritten: cardinal;
AUtf8: UTF8string;
ADeviceMode: THandle;
i : integer;
SNO : String;
Number : String[2];
Desc:String;
f : TextFile;

begin
  wordsearchfrm.DBGrid1.DataSource.DataSet.First;

  repeat
  //choose printer (a windows generic printer works fine)
  Printer.PrinterIndex := Printorexcelfrm.cboPrinter.ItemIndex;
  Printer.GetPrinter(ADevice, ADeviceName, ADevicePort, ADeviceMode);

  //Obtain a handle to the printer
  if not OpenPrinter(ADevice, PrinterHandle, nil)
  then Exit;

  //Fill in the structure with info about this "document"
  DocInfo.pDocName := PChar('Ticket');
  DocInfo.pOutputFile := nil;
  DocInfo.pDatatype := 'RAW';

  //Inform the spooler the document is beginning
  dwJob := StartDocPrinter(PrinterHandle, 1, @DocInfo);
  if dwJob = 0 then begin
  ClosePrinter(PrinterHandle);
  PrinterHandle := 0;
  Exit;
  end;

  //Start a page
  if not StartPagePrinter(PrinterHandle) then begin
  EndDocPrinter(PrinterHandle);
  ClosePrinter(PrinterHandle);
  PrinterHandle := 0;
  Exit;
  end;
  /////////////////////////////////////
 

  //your epl code...
  //NOT INCLUDED
  wordsearchfrm.DBGrid1.DataSource.DataSet.next;

   //End the page
  if not EndPagePrinter(PrinterHandle) then begin
  EndDocPrinter(PrinterHandle);
  ClosePrinter(PrinterHandle);
  PrinterHandle := 0;
  Exit;
  end;
//end;

  //Inform the spooler that the document is ending
  if not EndDocPrinter(PrinterHandle) then begin
  ClosePrinter(PrinterHandle);
  PrinterHandle := 0;
  Exit;
  end;

  //Tidy up the printer handle
  ClosePrinter(PrinterHandle);
  PrinterHandle := 0;

until wordsearchfrm.DBGrid1.DataSource.DataSet.Eof;