@nikiphoros/capacitor-pos-printer
v1.0.0
Published
A custom Capacitor plugin that integrates the Cashino CSN Thermal Printer Android SDK (CSNPrinterSDK.jar) into Ionic/Angular applications.
Readme
@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
npm install @nikiphoros/capacitor-csn-printer
npx cap syncAndroid Requirements
Your Android device must support USB OTG / USB Host mode.
Add this to AndroidManifest.xml if required:
<uses-feature android:name="android.hardware.usb.host" />Import Plugin
import { registerPlugin } from '@capacitor/core';
const Csnprinter = registerPlugin('Csnprinter');or
import { Csnprinter } from '@nikiphoros/capacitor-csn-printer';Basic Printing Workflow
Typical printing sequence:
- Open printer
- Set alignment
- Print text or image
- Feed paper
- Cut paper
- Close printer
Usage Examples
Open Printer
Opens the USB printer connection and requests permission if required.
await Csnprinter.open();Print Text
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.
await Csnprinter.align({
num: 1
});Alignment Values
Value Alignment
0 Left 1 Center 2 Right
Print Image
Print an image directly from a URL.
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.
await Csnprinter.feedLine();Useful for spacing between printed content.
Full Cut Paper
Cuts the paper after printing.
await Csnprinter.fullCutPaper();Reset Printer
Resets the printer state.
await Csnprinter.reset();Close Printer
Closes the USB connection to the printer.
await Csnprinter.close();Complete Example
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
