
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@decky.fx/react-native-printer
Advanced tools
Warning Experimental
printing on react-native
modified from https://github.com/DantSu/ESCPOS-ThermalPrinter-Android, written in full Kotlin, using latest sdk, and modern language like coroutines etc.
<img> tag's payloadconst data = '<img>file:///sdcard/image.png</img>'
npm install @decky.fx/react-native-printer --save
or
yarn add @decky.fx/react-native-printer
1.0.5-g
yarn installcd example && yarn installyarn install --ignore-enginesv16.16.0 or v18.16.1yarn startto use in older react-native project you may need to edit project build.gradle file
edit
minCompileSdk
add
mavenCentral()
maven { url "https://maven.google.com" }
and
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22"
// Import modules
import {
RNPrinter,
DeviceScanner,
RNPrinterEventEmitter,
DeviceScannerEventEmitter,
} from '@decky.fx/react-native-printer';
// Listen various event
RNPrinterEventEmitter.onEvents((event, payload) => {});
DeviceScannerEventEmitter.onEvents((event, payload) => {});
// Scan usb devices
DeviceScanner.scan(DeviceScanner.SCAN_USB);
// Design the print output
const builder = new DesignBuilder(RNPrinter.PRINTING_LINES_MAX_CHAR_42);
builder.addLine('Print me');
builder.addLine(TagHelper.left('I am at left'));
builder.addLine(TagHelper.center('I am centered'));
builder.addLine(TagHelper.right('I am at right'));
builder.addLine(TagHelper.center(TagHelper.bold('I am bold')));
builder.addLine(TagHelper.center(TagHelper.underline('I am underlined')));
builder.addLine(TagHelper.center(TagHelper.barcode('barcode data')));
builder.addLine(TagHelper.center(TagHelper.qrcode('qrcode data')));
builder.addLine(TagHelper.center(TagHelper.image('image source')));
// Build printing job
const printer = {
connection: RNPrinter.PRINTER_CONNECTION_BLUETOOTH,
address: "00:00:00:00:00",
}
const jobId = await JobBuilder.begin();
await JobBuilder.selectPrinter(jobId, printer);
await JobBuilder.initializePrinter(jobId);
// Build the design
const designBuilder = new DesignBuilder(
RNPrinter.PRINTING_LINES_MAX_CHAR_40
);
designBuilder.addLine('Print something')
// Put all design
for (let i = 0; i < designBuilder.designs.length; i++) {
let line = designBuilder.designs[i]!!;
await JobBuilder.printLine(jobId, line);
}
await JobBuilder.cutPaper(jobId);
await JobBuilder.openCashBox(jobId);
// execute job
const job = await JobBuilder.build(jobId);
// RNPrinter.enqueuePrint(job);
RNPrinter.enqueuePrint(job, printer);
// Another way
RNPrinter.write(RNPrinter.PRINTER_CONNECTION_USB, '/dev/usb/001/003', `[C]<img>${imageUri}</img>\n"` + '[L]\n'
// Write to usb device
RNPrinter.write({
connection: RNPrinter.PRINTER_CONNECTION_USB,
address: '/dev/usb/001/003',
}, RNPrinter.TEST_PRINT_DESIGN);
// unsubscribe listeners if no longer needed
RNPrinterEventEmitter.offEvents();
DeviceScannerEventEmitter.offEvents();
Use \n to create a new line of text.
Add an alignment tag on a same line of text implicitly create a new column.
Column alignment tags :
[L] : left side alignment[C] : center alignment[R] : right side alignmentExample :
[L]Some text : One column aligned to left[C]Some text : One column aligned to center[R]Some text : One column aligned to right[L]Some text[L]Some other text : Two columns aligned to left. Some other text starts in the center of the paper.[L]Some text[R]Some other text : Two columns, first aligned to left, second aligned to right. Some other text is printed at the right of paper.[L]Some[R]text[R]here : Three columns.[L][R]text[R]here : Three columns. The first is empty but it takes a third of the available space.<font></font> tag allows you to change the font size and color. Default size is normal / black.
<font size='normal'>Some text</font> : Normal size
<font size='wide'>Some text</font> : Double width of medium size
<font size='tall'>Some text</font> : Double height of medium size
<font size='big'>Some text</font> : Double width and height of medium size
<font size='big-2'>Some text</font> : 3 x width and height
<font size='big-3'>Some text</font> : 4 x width and height
<font size='big-4'>Some text</font> : 5 x width and height
<font size='big-5'>Some text</font> : 6 x width and height
<font size='big-6'>Some text</font> : 7 x width and height
<font color='black'>Some text</font> : black text - white background
<font color='bg-black'>Some text</font> : white text - black background
<font color='red'>Some text</font> : red text - white background (Not working on all printer)
<font color='bg-red'>Some text</font> : white text - red background (Not working on all printer)
<b></b> tag allows you to change the font weight.
<b>Some text</b><u></u> tag allows you to underline the text.
<u>Some text</u> text underlined<u type='double'>Some text</u> text double-strike (Not working on all printer)<img></img> tag allows you to print image. Inside the tag you need to write a hexadecimal string of an image.
Use PrinterTextParserImg.bitmapToHexadecimalString to convert Drawable, BitmapDrawable or Bitmap to hexadecimal string.
<img>hexadecimal string of an image</img>⚠ WARNING ⚠ : This tag has several constraints :
<img></img> can have only one alignment tag and it must be at the beginning of the line.<img> must be directly preceded by nothing or an alignment tag ([L][C][R]).</img> must be directly followed by a new line \n.<img></img>.<barcode></barcode> tag allows you to print a barcode. Inside the tag you need to write the code number to print.
<barcode>451278452159</barcode> : (12 numbers)<barcode type='ean8'>4512784</barcode> : (7 numbers)<barcode type='upca' height='20'>4512784521</barcode> : (11 numbers)<barcode type='upce' height='25' width='50' text='none'>512789</barcode> : (6 numbers)<barcode type='128' width='40' text='above'>DantSu</barcode> : (string)⚠ WARNING ⚠ : This tag has several constraints :
<barcode></barcode> can have only one alignment tag and it must be at the beginning of the line.<barcode> must be directly preceded by nothing or an alignment tag ([L][C][R]).</barcode> must be directly followed by a new line \n.<barcode></barcode>.<qrcode></qrcode> tag allows you to print a QR code. Inside the tag you need to write the QR code data.
<qrcode>https://dantsu.com/</qrcode> :
Prints a QR code with a width and height of 20 millimeters.<qrcode size='25'>123456789</qrcode> :
Prints a QR code with a width and height of 25 millimeters.⚠ WARNING ⚠ : This tag has several constraints :
<qrcode></qrcode> can have only one alignment tag and it must be at the beginning of the line.<qrcode> must be directly preceded by nothing or an alignment tag ([L][C][R]).</qrcode> must be directly followed by a new line \n.<qrcode></qrcode>.See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
printing on react native
We found that @decky.fx/react-native-printer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.