From e7efb4ab1409763866264cc9d2d5503c579c839a Mon Sep 17 00:00:00 2001 From: jimmy5312 Date: Fri, 21 Oct 2022 00:18:38 +0800 Subject: [PATCH] Fix code128 barcode string length calculation --- packages/printer/src/utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/printer/src/utils.ts b/packages/printer/src/utils.ts index 342420d..3bce90f 100644 --- a/packages/printer/src/utils.ts +++ b/packages/printer/src/utils.ts @@ -12,7 +12,8 @@ export function getParityBit(str: string) { } export function codeLength(str: string) { - let buff = Buffer.from((str.length).toString(16), 'hex'); + const hex = Number(str.length).toString(16).padStart(2, '0') + let buff = Buffer.from(hex, 'hex'); return buff.toString(); }