unit ZPL_Delphi;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, PrinterLib,
  Controls, Forms,  Dialogs, ComCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

function UnicodeToAnsi(Str: String): AnsiString;
var
  Len: integer;
begin
  Len := Length(Str) * 2 + 1; // one for #0
  SetLength(Result, Len);
  Len := WideCharToMultiByte(CP_ACP, 0, PWideChar(Str), -1, PAnsiChar(Result),
    Len, nil, nil);
  SetLength(Result, Len);
end;

function AnsiToUnicode(Str: AnsiString): String;
var
  Len: integer;
begin
  Len := Length(Str) + 1;
  SetLength(Result, Len);
  Len := MultiByteToWideChar(CP_ACP, 0, PAnsiChar(Str), -1, PWideChar(Result),
    Len);
  SetLength(Result, Len); // end is #0
end;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  iResult: integer;
begin
  iResult := DemoPrinterCreator('HD100');
  if iResult = 0 then
  begin
    iResult := DemoPortOpen('USB');
    if iResult = 0 then
    begin
      //开始
      iResult := DemoStartFormat();

      //设置打印浓度
      iResult := DemoSetPrintDarkness(20);

      //设置是否切刀、剥离等
      iResult := DemoSetPrintMode('T','N');
      iResult := DemoSetPrintQuantity(1,0,1,'N');

      //设置是否翻转打印
      iResult := DemoSetPrintOrientation(180);

      //打印图片
      iResult := DemoPrintImage(100, 100, 'D:\\1.bmp');

      //打印Pdf417
      iResult := DemoPdf417(100, 250, 0, 2, 20, 2, 5, 5, 'N', '0010101101');

      //打印BarCode39条码
      iResult := DemoBarCode39(100, 400, 0, 3, 50, 'Y', 'Y', 'Y', '66886868');

      //打印CodeEan8条码
      iResult := DemoCodeEan8(100, 500, 0, 3, 60, 'Y', 'Y', '90381010');

      //打印UPC-A
      iResult := DemoUpcaBarcode(100, 600, 0, 3, 50, 'Y', 'Y', 'N', '47631664454');

      //打印UPC扩展条码
      iResult := DemoUpcExtensions(100, 700, 0, 3, 50, 'Y', 'Y', '01234');

      //打印二维码
      iResult := DemoQRCode(100, 800, 0, 1, 3, 'M', 7, '1000000001');

      //打印汉字
      iResult := DemoSetChangeFontEncoding(14);
      iResult := DemoText(100, 900, 16, 0, 40, 40, '你好');
      iResult := DemoText(300, 900, 16, 0, 40, 40, 'hello');
      iResult := DemoText(500, 900, 16, 0, 40, 40, 'こんにちは');

      //打印图形圆圈
      iResult := DemoGraphicCircle(100, 1000, 150, 5);

      //打印图形椭圆
      iResult := DemoGraphicEllipse(300, 1000, 150, 100, 10);

      //打印对角线
      iResult := DemoGraphicDiagonalLine(500, 1000, $52, 50, 50, 20);

      //打印图形框
      iResult := DemoGraphicBox(100, 1200, 100, 100, 60, 3);

      //打印符号
      iResult := DemoGraphicSymbol(300, 1200, 0, 200, 200, 'A');

      //结束
      iResult := DemoEndFormat();

      //删除打印机
      iResult := DemoPortClose();

      //销毁
      iResult := DemoPrinterDestroy();

    end
    else
    begin
        ShowMessage('Usb Device not found');
    end;
  end
  else
  begin
      ShowMessage('Printer not found');
  end;

end;

end.
