--- dao/DelphiScanner/LabelPrint.pas 2016/05/30 20:26:56 3037 +++ dao/DelphiScanner/LabelPrint.pas 2016/05/31 11:50:42 3038 @@ -6,7 +6,8 @@ ParentForm, PakkeshopLabels, Configuration, - StBarc; + StBarc, + PrtRaw; type @@ -22,6 +23,9 @@ procedure PrintDaodirekteLabel( RuteNummer, Kommentar, BoghandlerNavn : String) ; + procedure TestZpl(); + procedure PrintZPL( ZplData : string); + function GetPrinterCount() : Integer; private @@ -397,6 +401,105 @@ Result := p; end; +// Online zpl viewer +// http://labelary.com/viewer.html +procedure TLabelPrint.TestZpl(); +var + zpl: string; +begin + zpl := +'^XA'#13#10 + +'^PON'#13#10 + +'^FWN'#13#10 + + +'^FX Top section with company logo, name and address.'#13#10 + +'^CF0,60'#13#10 + +'^FO50,50^GB100,100,100^FS'#13#10+ +'^FO75,75^FR^GB100,100,100^FS'#13#10+ +'^FO88,88^GB50,50,50^FS'#13#10+ +'^FO220,50^FDInternational Shipping, Inc.^FS'#13#10+ +'^CF0,40'#13#10+ +'^FO220,100^FD1000 Shipping Lane^FS'#13#10+ +'^FO220,135^FDShelbyville TN 38102^FS'#13#10+ +'^FO220,170^FDUnited States (USA)^FS'#13#10+ +'^FO50,250^GB700,1,3^FS'#13#10 + +'^XZ'#13#10 + ; + + PrintZpl(zpl); +end; + +procedure TLabelPrint.PrintZPL( ZplData : string); +var + ADevice, ADeviceName, ADevicePort: array[0..255]of Char; + PrinterHandle: THandle; + DocInfo: TDocInfo1; + dwJob: cardinal; + dwBytesWritten: cardinal; + AUtf8: UTF8string; + ADeviceMode: THandle; + +begin + + + Printer.GetPrinter(ADevice, ADeviceName, ADevicePort, ADeviceMode); + + if not OpenPrinter(ADevice, PrinterHandle, nil) then + begin + Exit; + parentForm.Msg('error on openprinter'); + end; + + //Fill in the structure with info about this "document" + DocInfo.pDocName := PChar('Spooler Document Name'); + 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 zebra code... + AUtf8 := UTF8string(ZplData); + WritePrinter(PrinterHandle, @AUtf8[1], Length(AUtf8), dwBytesWritten); + + //End the page + if not EndPagePrinter(PrinterHandle) then + begin + EndDocPrinter(PrinterHandle); + ClosePrinter(PrinterHandle); + PrinterHandle := 0; + Exit; + 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; + +end; + function TLabelPrint.GetPrinterCount() : Integer; begin