npm package: @nikiphoros/capacitor-pos-printer
Description: A custom Capacitor plugin that integrates the Cashino CSN Thermal Printer Android SDK (CSNPrinterSDK.jar) into Ionic/Angular applications.
Author: nikiphoros
Latest version: 1.0.0

# @nikiphoros/capacitor-csn-printer

A custom **Capacitor plugin** that integrates the **Cashino CSN Thermal
Printer Android SDK (CSNPrinterSDK.jar)** into **Ionic / Angular
applications**.

This plugin enables direct communication with **USB POS thermal
printers** using the official **CSN Android SDK**.

Tested devices:

-   **ASN-A1 (2 inch thermal printer)**
-   **HOIN (3 inch thermal printer)**

⚠️ **Android Only**\
This plugin does **NOT support Web or iOS**.

------------------------------------------------------------------------

# Features

-   Connect to CSN USB thermal printers
-   Print text
-   Print images from URL
-   Control text alignment
-   Feed paper
-   Cut paper
-   Reset printer
-   Close printer connection

------------------------------------------------------------------------

# Platform Support

  Platform   Supported
  ---------- -----------
  Android    ✅
  iOS        ❌
  Web        ❌

------------------------------------------------------------------------

# Installation

``` bash
npm install @nikiphoros/capacitor-csn-printer
npx cap sync
```

------------------------------------------------------------------------

# Android Requirements

Your Android device must support **USB OTG / USB Host mode**.

Add this to **AndroidManifest.xml** if required:

``` xml
<uses-feature android:name="android.hardware.usb.host" />
```

------------------------------------------------------------------------

# Import Plugin

``` ts
import { registerPlugin } from '@capacitor/core';

const Csnprinter = registerPlugin('Csnprinter');
```

or

``` ts
import { Csnprinter } from '@nikiphoros/capacitor-csn-printer';
```

------------------------------------------------------------------------

# Basic Printing Workflow

Typical printing sequence:

1.  Open printer
2.  Set alignment
3.  Print text or image
4.  Feed paper
5.  Cut paper
6.  Close printer

------------------------------------------------------------------------

# Usage Examples

## Open Printer

Opens the USB printer connection and requests permission if required.

``` ts
await Csnprinter.open();
```

------------------------------------------------------------------------

# Print Text

``` ts
await Csnprinter.textOut({
  text: "Hello World",
  nOrgx: 0,
  nWidth: 0,
  nHight: 0,
  nFtype: 0,
  nFstyle: 0
});
```

### Parameters

  Parameter   Type     Description
  ----------- -------- ----------------------------
  text        string   Text to print
  nOrgx       number   Horizontal origin position
  nWidth      number   Font width scaling
  nHight      number   Font height scaling
  nFtype      number   Font type
  nFstyle     number   Font style

------------------------------------------------------------------------

# Align Text

Controls text alignment.

``` ts
await Csnprinter.align({
  num: 1
});
```

### Alignment Values

  Value   Alignment
  ------- -----------
  0       Left
  1       Center
  2       Right

------------------------------------------------------------------------

# Print Image

Print an image directly from a URL.

``` ts
await Csnprinter.printPicture({
  URL: "https://yourdomain.com/logo.png"
});
```

The plugin internally downloads the image and sends it to the printer.

------------------------------------------------------------------------

# Feed Line

Feeds the paper by one line.

``` ts
await Csnprinter.feedLine();
```

Useful for spacing between printed content.

------------------------------------------------------------------------

# Full Cut Paper

Cuts the paper after printing.

``` ts
await Csnprinter.fullCutPaper();
```

------------------------------------------------------------------------

# Reset Printer

Resets the printer state.

``` ts
await Csnprinter.reset();
```

------------------------------------------------------------------------

# Close Printer

Closes the USB connection to the printer.

``` ts
await Csnprinter.close();
```

------------------------------------------------------------------------

# Complete Example

``` ts
async function printSample() {

  await Csnprinter.open();

  await Csnprinter.align({ num: 1 });

  await Csnprinter.textOut({
    text: "MY SHOP",
    nOrgx: 0,
    nWidth: 0,
    nHight: 0,
    nFtype: 0,
    nFstyle: 1
  });

  await Csnprinter.feedLine();

  await Csnprinter.align({ num: 0 });

  await Csnprinter.textOut({
    text: "Item 1    100",
    nOrgx: 0,
    nWidth: 0,
    nHight: 0,
    nFtype: 0,
    nFstyle: 0
  });

  await Csnprinter.feedLine();

  await Csnprinter.textOut({
    text: "Total: 100",
    nOrgx: 0,
    nWidth: 0,
    nHight: 0,
    nFtype: 0,
    nFstyle: 1
  });

  await Csnprinter.feedLine();
  await Csnprinter.feedLine();

  await Csnprinter.fullCutPaper();

  await Csnprinter.close();
}
```

------------------------------------------------------------------------

# API Reference

## open()

Opens printer connection.

    open() => Promise<void>

------------------------------------------------------------------------

## align()

Set text alignment.

    align({ num: number })

------------------------------------------------------------------------

## textOut()

Print text.

    textOut({
      text: string,
      nOrgx: number,
      nWidth: number,
      nHight: number,
      nFtype: number,
      nFstyle: number
    })

------------------------------------------------------------------------

## printPicture()

Print image from URL.

    printPicture({
      URL: string
    })

------------------------------------------------------------------------

## feedLine()

Feeds paper.

    feedLine()

------------------------------------------------------------------------

## fullCutPaper()

Cuts the paper.

    fullCutPaper()

------------------------------------------------------------------------

## reset()

Reset printer.

    reset()

------------------------------------------------------------------------

## close()

Close printer connection.

    close()

------------------------------------------------------------------------

# Tested Printers

-   ASN-A1 (2 inch thermal printer)
-   HOIN (3 inch thermal printer)

Other **CSN SDK compatible printers may also work**.

------------------------------------------------------------------------

# Notes

-   Printer must be connected via **USB OTG**
-   The application will automatically request **USB permission**
-   Only compatible with **CSN Printer SDK based devices**

------------------------------------------------------------------------

# License

MIT

------------------------------------------------------------------------

# Author

**Nikhil Shende**

GitHub\
https://github.com/nikiphoros