@bobfrankston/brother-label
v1.0.14
Published
API and CLI for printing labels on Brother P-touch printers
Downloads
56
Maintainers
Readme
@bobfrankston/brother-label
Print labels to Brother P-touch label printers from Node.js. Supports text, HTML, images, and QR codes.
Installation
npm install - @bobfrankston/brother-labelCommand Line Usage
Print text
brother-print print "Hello World"
brother-print print "Line 1\\nLine 2" # Multi-linePrint QR code
brother-print qr "https://example.com"
brother-print qr "https://example.com" -l "My Site" # With text label
brother-print qr "any data" -o qr.png # Save to filePrint HTML
brother-print html label.htmlInline QR codes in HTML
Use <img qr="data"> to embed QR codes directly in HTML - they're converted to base64 at render time:
<img qr="https://example.com" style="width:10mm; height:10mm">
<img qr="any data here" class="my-qr">Multi-segment labels
Combine multiple -text and -qr segments on a single label, printed side-by-side in order:
brother-print -text "Hello" -qr "https://example.com"
brother-print -text "Top\nBottom" -qr "https://example.com" -text "More text"
brother-print -t "Label" -q "data" -o combined.pngPrint image
brother-print image photo.pngPreview (save without printing)
brother-print preview "Test Label" -o preview.pngConfiguration
brother-print config --show # Show current config
brother-print config -s 12 # Set default tape size
brother-print config -p "Brother PT-P710BT" # Set default printer
brother-print list # List Brother printersOptions
| Option | Description |
|--------|-------------|
| -t, --text | Force input as literal text; repeatable for multi-segment labels |
| -q, --qr | QR code segment; repeatable for multi-segment labels |
| -s, --tape <size> | Tape size: 6, 9, 12, 18, 24 (mm) |
| -p, --printer <name> | Printer name |
| -o, --output <file> | Save to file instead of printing |
| -a, --aspect <ratio> | Aspect ratio width:height for HTML (e.g., 3.5:2) |
| -H, --height <size> | Text height: 12mm, .5in, or 50% (of tape height) |
| -w, --html | Force input as HTML file path |
| -i, --image | Force input as image file path |
Single-hyphen long options are supported: -text works the same as --text, -tape as --tape, etc. Single letters are strict: -t means --text, not the start of -tape.
API Usage
Print text
import { print } from "@bobfrankston/brother-label";
await print({ text: "Hello World" });
await print({ text: "Hello", tape: 12 }); // 12mm tapePrint QR code
import { print, render } from "@bobfrankston/brother-label";
// Print QR code
await print({ qr: "https://example.com" });
// QR code with text label
await print({ qr: "https://example.com", qrLabel: "My Site" });
// Render to buffer without printing
const buffer = await render({ qr: "https://example.com" });Print HTML
// From file
await print({ htmlPath: "label.html" });
// Inline HTML
await print({
html: "<div style='font-size:24px'>Hello</div>",
basePath: __dirname // For resolving relative resources
});
// With aspect ratio
await print({ htmlPath: "label.html", aspect: "4:1" });
// HTML with inline QR codes - <img qr="..."> auto-converted to base64
await print({
html: `<img qr="https://example.com" style="width:10mm">`,
});Print image
// From file
await print({ imagePath: "photo.png" });
// From buffer
await print({ imageBuffer: fs.readFileSync("photo.png") });Configuration
import { getConfig, setConfig, listPrinters } from "@bobfrankston/brother-label";
// Get current config
const config = getConfig();
console.log(config.defaultTape); // 12
console.log(config.defaultPrinter); // "Brother PT-P710BT"
// Set defaults
setConfig({ defaultTape: 24, defaultPrinter: "Brother PT-P710BT" });
// List printers
const printers = await listPrinters();
printers.forEach(p => console.log(p.name));Render without printing
import { render } from "@bobfrankston/brother-label";
const buffer = await render({ text: "Hello" });
fs.writeFileSync("label.png", buffer);API Reference
Types
type TapeSize = 6 | 9 | 12 | 18 | 24;
interface PrintOptions {
// Content (exactly one required)
text?: string; // Plain text
html?: string; // Inline HTML
htmlPath?: string; // Path to HTML file
textFile?: string; // Path to text file
imagePath?: string; // Path to image file
imageBuffer?: Buffer; // Image buffer
qr?: string; // QR code data
// Settings
tape?: TapeSize; // Tape size in mm
printer?: string; // Printer name
basePath?: string; // Base path for HTML resources
aspect?: string; // Aspect ratio for HTML (e.g., "4:1")
qrLabel?: string; // Text label beside QR code
}
interface PrintResult {
image: Buffer; // The rendered image
}Functions
| Function | Description |
|----------|-------------|
| print(options) | Render and print a label |
| render(options) | Render label to PNG buffer |
| renderSegments(segments, tape?, textHeight?) | Render multiple text/qr segments side-by-side |
| printSegments(segments, options?) | Render and print multiple segments |
| getConfig() | Get current configuration |
| setConfig(config) | Set default tape/printer |
| getConfigPath() | Get config file path |
| listPrinters() | List Brother printers |
Supported Printers
- Brother PT-P710BT (tested)
- Other Brother P-touch printers (should work)
- Brother QL series (untested)
Requirements
- Windows (uses Windows printing APIs)
- Node.js 20+
- Puppeteer (for HTML rendering)
