Compare commits

..

5 Commits

Author SHA1 Message Date
c858e3e9c4 added qrcode 2022-02-28 13:44:47 +01:00
ca3fadde1c added 2d barcode 2022-02-28 13:36:29 +01:00
f7b41cf647 added basic README 2022-02-28 01:35:19 +01:00
2b9f62b239 ahh yes the english language 2022-02-28 01:31:08 +01:00
1db2e55b2b added line spacing 2022-02-28 01:25:55 +01:00
6 changed files with 148 additions and 4 deletions

View File

@@ -50,6 +50,13 @@ public class PrinterController : Controller
case "feed": case "feed":
parsedInstruction = instruction.Deserialize<FeedInstruction>(); parsedInstruction = instruction.Deserialize<FeedInstruction>();
break; break;
case "barcode2d":
parsedInstruction = instruction.Deserialize<Barcode2D>();
break;
case "qrcode":
parsedInstruction = instruction.Deserialize<QRCode>();
break;
default: default:
return BadRequest(); return BadRequest();
} }

27
Instructions/Barcode2D.cs Normal file
View File

@@ -0,0 +1,27 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using ESCPOS_NET.Emitters;
public class Barcode2D : BaseInstruction
{
[DataMember(IsRequired = true)]
public string? data { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public TwoDimensionCodeType barcodeType {get; set; } = TwoDimensionCodeType.PDF417;
[JsonConverter(typeof(JsonStringEnumConverter))]
public Size2DCode size {get; set; } = Size2DCode.NORMAL;
[JsonConverter(typeof(JsonStringEnumConverter))]
public CorrectionLevel2DCode correctionLevel {get; set; } = CorrectionLevel2DCode.PERCENT_7;
public override List<byte[]> GetInstructions()
{
var commands = new List<byte[]>();
commands.Add(e.Print2DCode(barcodeType,data,size,correctionLevel));
return commands;
}
}

View File

@@ -18,7 +18,7 @@ public class BarcodeInstruction : BaseInstruction
public Alignment alignment {get; set; } = Alignment.Left; public Alignment alignment {get; set; } = Alignment.Left;
[JsonConverter(typeof(JsonStringEnumConverter))] [JsonConverter(typeof(JsonStringEnumConverter))]
public BarLabelPrintPosition lablePos {get; set; } = BarLabelPrintPosition.Below; public BarLabelPrintPosition labelPos {get; set; } = BarLabelPrintPosition.Below;
// [JsonConverter(typeof(JsonStringEnumConverter))] // [JsonConverter(typeof(JsonStringEnumConverter))]
// public BarWidth width { get; set; } = BarWidth.Default; // public BarWidth width { get; set; } = BarWidth.Default;
@@ -36,8 +36,8 @@ public class BarcodeInstruction : BaseInstruction
commands.Add(alignmentCommand(alignment)); commands.Add(alignmentCommand(alignment));
if (lablePos != BarLabelPrintPosition.Below){ if (labelPos != BarLabelPrintPosition.Below){
commands.Add(e.SetBarLabelPosition(lablePos)); commands.Add(e.SetBarLabelPosition(labelPos));
} }
if (height > 0) if (height > 0)

26
Instructions/QRCode.cs Normal file
View File

@@ -0,0 +1,26 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using ESCPOS_NET.Emitters;
public class QRCode : BaseInstruction
{
[DataMember(IsRequired = true)]
public string? data { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public TwoDimensionCodeType barcodeType {get; set; } = TwoDimensionCodeType.QRCODE_MODEL2;
[JsonConverter(typeof(JsonStringEnumConverter))]
public Size2DCode size {get; set; } = Size2DCode.NORMAL;
[JsonConverter(typeof(JsonStringEnumConverter))]
public CorrectionLevel2DCode correctionLevel {get; set; } = CorrectionLevel2DCode.PERCENT_7;
public override List<byte[]> GetInstructions()
{
var commands = new List<byte[]>();
commands.Add(e.PrintQRCode(data,barcodeType,size,correctionLevel));
return commands;
}
}

View File

@@ -15,7 +15,7 @@ public class TextInstruction : BaseInstruction
public bool doubleHeight {get; set; } = false; public bool doubleHeight {get; set; } = false;
public bool doubleWidth {get; set; } = false; public bool doubleWidth {get; set; } = false;
public bool fontB {get; set; } = false; public bool fontB {get; set; } = false;
public int lineSpacing {get; set; } = -1;
public bool newLine { get; set; } = true; public bool newLine { get; set; } = true;
@@ -27,6 +27,10 @@ public class TextInstruction : BaseInstruction
commands.AddRange(setStyles()); commands.AddRange(setStyles());
if (lineSpacing >= 0){
commands.Add(e.SetLineSpacingInDots(lineSpacing));
}
if (newLine) if (newLine)
{ {
commands.Add(e.PrintLine(text)); commands.Add(e.PrintLine(text));
@@ -40,6 +44,10 @@ public class TextInstruction : BaseInstruction
commands.Add(e.SetStyles(PrintStyle.None)); commands.Add(e.SetStyles(PrintStyle.None));
} }
if (lineSpacing >= 0){
commands.Add(e.ResetLineSpacing());
}
return commands; return commands;
} }

76
README.md Normal file
View File

@@ -0,0 +1,76 @@
Provide a JSON REST API to `ESC/POS` printers. Most of the time these printers will be thermal printers.
# Usage
GET `/api/printer/name` to get the UUID of the printer.
GET `/api/printer/status` to get information about the current state of the printer.
To actually print something use POST `/api/printer/print`. The body is an JSON array of print instructions. Following instructions are available.
## Feed
`lines` and `dots` can be used at the same time.
```json
{
"type":"feed",
"lines":4,
"dots":50
}
```
## Text
Only `text` is required.
`alignment`: Can be `Right`,`Left`,`Center`. Default is `Left`.
`underline`,`bold`,`doubleHeight`,`doubleWidth` are obvious and default to `false`.
`fontB`: Use different font. Based on printer model. Default is `false`.
`lineSpacing`: Line spacings in dots. Default is unset.
`newLine`: Insert a new line after printing the text. Default is `true`.
```json
{
"type":"text",
"text":"Hello world",
"alignment":"Center",
"underline": false,
"bold": false,
"doubleHeight":false,
"doubleWidth":false,
"fontB":false,
"lineSpacing":23,
"newLine":true
}
```
## Barcode
`barcode`: Value of the barcode. Depending on the `barcodeType` it may only contain numeric characters. Require.
`barcodeType`: What type of barcode. Possible values are: `CODE128`, `UPC_A`,`UPC_E`,`JAN13_EAN13`,`JAN8_EAN8`,`CODE39`,`ITF`,`CODABAR_NW_7`,`CODE93`,`GS1_128`,`GS1_DATABAR_OMNIDIRECTIONAL`, `GS1_DATABAR_TRUNCATED`,`GS1_DATABAR_LIMITED`,`GS1_DATABAR_EXPANDED`. Default is `CODE128`. Depending on the printer modell not all types are supported.
`barcodeCode`: I honestly have no idea what exactly this changes. But it changes something. Default is `CODE_B`.
`alignment`: Just like `alignment` in the "Text" instruction.
`labelPos`: Position of the value of the barcode in text form. Possible values are : `None`, `Above`, `Below`, `Both`. Default is `Below`.
`height`: Height of the barcode in dots. Default is unset.
```json
{
"type":"barcode",
"barcode":"348234445AA",
"barcodeType":"CODE128",
"barcodeCode":"CODE_B",
"alignment":"Center",
"labelPos":"None",
"height":45,
}
```