New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sdk-printer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sdk-printer

printer for kiosk

latest
npmnpm
Version
0.0.7
Version published
Weekly downloads
225
Maintainers
1
Weekly downloads
 
Created
Source

sdk-printer

printer for kiosk

Install

npm install sdk-printer
npx cap sync

API

  • connect()
  • close()
  • resetFont()
  • getStatus()
  • outputString(...)
  • outputStringLn(...)
  • printBarcode(...)
  • printQRcode(...)
  • cutPaper()
  • printFormattedText(...)
  • printText(...)
  • doFunction(...)

connect()

connect() => Promise<{ success: boolean; message: string; }>

Returns: Promise<{ success: boolean; message: string; }>

close()

close() => Promise<void>

resetFont()

resetFont() => Promise<void>

getStatus()

getStatus() => Promise<{ status1: number; status2: number; }>

Returns: Promise<{ status1: number; status2: number; }>

outputString(...)

outputString(options: { str: string; }) => Promise<void>
ParamType
options{ str: string; }

outputStringLn(...)

outputStringLn(options: { str: string; }) => Promise<void>
ParamType
options{ str: string; }

printBarcode(...)

printBarcode(options: { type: number; str: string; }) => Promise<void>
ParamType
options{ type: number; str: string; }

printQRcode(...)

printQRcode(options: { data: string; }) => Promise<void>
ParamType
options{ data: string; }

cutPaper()

cutPaper() => Promise<void>

printFormattedText(...)

printFormattedText(options: { text: string; }) => Promise<void>
ParamType
options{ text: string; }

printText(...)

printText(options: { text: string; logoBase64?: string; }) => Promise<void>
ParamType
options{ text: string; logoBase64?: string; }

doFunction(...)

doFunction(options: { func: number; param1: number; param2: number; }) => Promise<void>
ParamType
options{ func: number; param1: number; param2: number; }

Constants for doFunction

export const TX_CONSTANTS = {
  // --- TRẠNG THÁI ON/OFF ---
  TX_ON: 1,
  TX_OFF: 0,

  // --- 1. CỠ CHỮ (TX_FONT_SIZE) ---
  // param1: Chiều rộng (0-7), param2: Chiều cao (0-7)
  // 0: Bình thường (1x), 1: 2x, 2: 3x ... 7: 8x
  TX_FONT_SIZE: 1,
  TX_SIZE_1X: 0,
  TX_SIZE_2X: 1,
  TX_SIZE_3X: 2,
  TX_SIZE_4X: 3,
  TX_SIZE_8X: 7,

  // --- 2. GẠCH CHÂN (TX_FONT_ULINE) ---
  TX_FONT_ULINE: 2,

  // --- 3. IN ĐẬM (TX_FONT_BOLD) ---
  TX_FONT_BOLD: 3,

  // --- 4. CHỌN FONT (TX_SEL_FONT) ---
  TX_SEL_FONT: 4,
  TX_FONT_A: 0, // 12x24 (Font chuẩn)
  TX_FONT_B: 1, // 9x17 (Font nhỏ)

  // --- 5. XOAY 90 ĐỘ (TX_FONT_ROTATE) ---
  TX_FONT_ROTATE: 5,

  // --- 6. CĂN LỀ (TX_ALIGN) ---
  TX_ALIGN: 6,
  TX_ALIGN_LEFT: 0,
  TX_ALIGN_CENTER: 1,
  TX_ALIGN_RIGHT: 2,

  // --- 7. CHẾ ĐỘ TIẾNG VIỆT/TRUNG (TX_CHINESE_MODE) ---
  TX_CHINESE_MODE: 7,

  // --- 10. ĐẨY GIẤY (TX_FEED) ---
  // Đơn vị: 0.125mm (Ví dụ feed 10mm thì param1 = 80)
  TX_FEED: 10,

  // --- 12. CẮT GIẤY (TX_CUT) ---
  TX_CUT: 12,
  TX_CUT_FULL: 0, // Cắt đứt hoàn toàn (Có check black mark)
  TX_CUT_PARTIAL: 1, // Cắt 1 phần (Có check black mark)
  TX_PURECUT_FULL: 2, // Cắt đứt hoàn toàn (Không check black mark - Thường dùng cái này)
  TX_PURECUT_PARTIAL: 3, // Cắt 1 phần (Không check black mark)

  // --- 14. KHOẢNG CÁCH DÒNG (TX_LINE_SP) ---
  TX_LINE_SP: 14,

  // --- 15. ĐẢO MÀU ĐEN TRẮNG (TX_BW_REVERSE) ---
  TX_BW_REVERSE: 15,

  // --- 16. LỘN NGƯỢC ĐẦU (TX_UPSIDE_DOWN) ---
  TX_UPSIDE_DOWN: 16,

  // --- 22. IN LOGO (TX_PRINT_LOGO) ---
  TX_PRINT_LOGO: 22,
  TX_LOGO_1X1: 0, // Kích thước thật

  // --- 23. MÃ VẠCH (BARCODE) ---
  TX_BARCODE_HEIGHT: 23, // Chiều cao
  TX_BARCODE_WIDTH: 24, // Độ rộng nét (>=2)
  TX_BARCODE_FONT: 25, // Vị trí chữ số HRI
  TX_BAR_FONT_NONE: 0,
  TX_BAR_FONT_UP: 1,
  TX_BAR_FONT_DOWN: 2, // Chữ nằm dưới mã vạch
  TX_BAR_FONT_BOTH: 3,

  // --- 26. ĐẨY GIẤY NGƯỢC (TX_FEED_REV) ---
  TX_FEED_REV: 26,

  // --- 27. QR CODE SIZE (TX_QR_DOTSIZE) ---
  TX_QR_DOTSIZE: 27, // 2 < param1 < 10 (Thường dùng 6)

  // --- 28. QR ERROR LEVEL (TX_QR_ERRLEVEL) ---
  TX_QR_ERRLEVEL: 28,
  TX_QR_ERRLEVEL_L: 0x31,
  TX_QR_ERRLEVEL_M: 0x32, // Trung bình (Thường dùng)
  TX_QR_ERRLEVEL_Q: 0x33,
  TX_QR_ERRLEVEL_H: 0x34, // Cao nhất
};

Examples

Kết nối máy in

const connectPrinter = async () => {
  try {
    const res = await PrinterPlugin.connect();
    if (res.success) {
      console.log('✅ Kết nối thành công:', res.message);
    }
  } catch (err: any) {
    console.error('❌ Kết nối thất bại:', err.message);
  }
};

In hóa đơn

// Hàm helper in 2 cột căn đều
const printTwoCol = async (left: string, right: string) => {
  const TOTAL_WIDTH = 32;
  const spaceLen = Math.max(0, TOTAL_WIDTH - left.length - right.length);
  const line = left + ' '.repeat(spaceLen) + right;
  await PrinterPlugin.outputStringLn({ str: line });
};

// In hóa đơn mẫu
const printReceipt = async () => {
  try {
    await PrinterPlugin.resetFont();

    // Header - Center, Bold, Large
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_ALIGN,
      param1: TX_CONSTANTS.TX_ALIGN_CENTER,
      param2: 0,
    });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_ON,
      param2: 0,
    });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_SIZE,
      param1: TX_CONSTANTS.TX_SIZE_2X,
      param2: TX_CONSTANTS.TX_SIZE_2X,
    });
    await PrinterPlugin.outputStringLn({ str: 'RECEIPT' });

    // Reset size & bold
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_SIZE,
      param1: TX_CONSTANTS.TX_SIZE_1X,
      param2: TX_CONSTANTS.TX_SIZE_1X,
    });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_OFF,
      param2: 0,
    });
    await PrinterPlugin.outputStringLn({ str: 'Date: 20/12/2025' });

    // Items
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_ALIGN,
      param1: TX_CONSTANTS.TX_ALIGN_LEFT,
      param2: 0,
    });
    await PrinterPlugin.outputStringLn({ str: '--------------------------------' });
    await printTwoCol('Item', 'Price');
    await PrinterPlugin.outputStringLn({ str: '--------------------------------' });

    const items = [
      { name: 'Coffee', price: 50000 },
      { name: 'Tea', price: 30000 },
    ];

    for (const item of items) {
      await printTwoCol(item.name, item.price.toString());
    }

    // Total
    await PrinterPlugin.outputStringLn({ str: '--------------------------------' });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_ON,
      param2: 0,
    });
    await printTwoCol('Total', '80000');
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_OFF,
      param2: 0,
    });

    // Footer
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_ALIGN,
      param1: TX_CONSTANTS.TX_ALIGN_CENTER,
      param2: 0,
    });
    await PrinterPlugin.outputStringLn({ str: 'Thank you!' });

    // Cut paper
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FEED,
      param1: 100,
      param2: 0,
    });
    await PrinterPlugin.cutPaper();

    console.log('✅ In thành công');
  } catch (err: any) {
    console.error('❌ Lỗi in:', err.message);
  }
};

Keywords

capacitor

FAQs

Package last updated on 31 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts