Share via


書式設定における Epson ESC/POS

POS プリンターで、ESC/POS コマンド言語を使用して、太字、倍角文字など、テキストの書式を設定する方法について説明します。

重要な API

ESC/POS の使い方

Windows Point of Service では、複数の Epson TM シリーズ プリンターを含むさまざまなプリンターがサポートされています (サポートされているプリンターの完全な一覧については、「 PointofService プリンター 」ページを参照してください)。 Windows では、ESC/POS プリンター制御言語を使用した印刷をサポートしています。この制御言語により、お使いのプリンターと通信するときに、効率的で実用的なコマンドを使用できます。

ESC/POS は、Epson が開発したコマンド システムで、広範囲の POS プリンター システムで使用されています。どのプリンターにも適用可能にすることで、コマンド セットの非互換性を回避することを目的としています。 現在のほとんどのプリンターでは、ESC/POS がサポートされています。

すべてのコマンドは、ESC 文字 (ASCII 27、16 進の 1B) または GS (ASCII 29、16 進の 1D) で始まり、その後にコマンドを指定する別の文字が続きます。 通常のテキストは単純にプリンターに送信され、改行で区切られます。

Windows PointOfService API では、その機能の大半を Print() または PrintLine() メソッドを通して提供します。 ただし、特定の書式を設定する、または特定のコマンドを送信するには、ESC/POS コマンドを使用して文字列として作成し、プリンターに送信する必要があります。

文字および倍角文字を使用する例

次の例は、ESC/POS コマンドを使用して、太字および倍角文字で印刷する方法を示しています。 各コマンドが文字列として作成され、印刷ジョブの呼び出しに挿入されていることに注意してください。

// … prior plumbing code removed for brevity
// this code assumed you've already created a receipt print job (printJob)
// and also that you've already checked the PosPrinter Capabilities to
// verify that the printer supports Bold and DoubleHighDoubleWide print modes

const string ESC = "\u001B";
const string GS = "\u001D";
const string InitializePrinter = ESC + "@";
const string BoldOn = ESC + "E" + "\u0001";
const string BoldOff = ESC + "E" + "\0";
const string DoubleOn = GS + "!" + "\u0011";  // 2x sized text (double-high + double-wide)
const string DoubleOff = GS + "!" + "\0";

printJob.Print(InitializePrinter);
printJob.PrintLine("Here is some normal text.");
printJob.PrintLine(BoldOn + "Here is some bold text." + BoldOff);
printJob.PrintLine(DoubleOn + "Here is some large text." + DoubleOff);

printJob.ExecuteAsync();

使用可能なコマンドを含む ESC/POS の詳細については、 ESC/POS コマンド リファレンス リビジョン 2.60 を参照してください。 Windows.Devices.PointOfService と利用可能な機能について詳しくは、MSDN の「PointofService プリンター」をご覧ください。