{"id":15305176,"url":"https://github.com/eddyverbruggen/nativescript-star-printer","last_synced_at":"2025-04-14T23:13:25.144Z","repository":{"id":57308834,"uuid":"88278770","full_name":"EddyVerbruggen/nativescript-star-printer","owner":"EddyVerbruggen","description":":star2: Print directly to Star Micronics printers from your NativeScript app! http://www.starmicronics.com/","archived":false,"fork":false,"pushed_at":"2023-04-18T09:58:59.000Z","size":67710,"stargazers_count":32,"open_issues_count":13,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-14T23:12:59.885Z","etag":null,"topics":["cashdrawer","nativescript","nativescript-plugin","printer","star","stario"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EddyVerbruggen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-14T15:20:50.000Z","updated_at":"2024-05-30T15:57:56.000Z","dependencies_parsed_at":"2025-02-26T05:42:00.157Z","dependency_job_id":null,"html_url":"https://github.com/EddyVerbruggen/nativescript-star-printer","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EddyVerbruggen%2Fnativescript-star-printer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EddyVerbruggen%2Fnativescript-star-printer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EddyVerbruggen%2Fnativescript-star-printer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EddyVerbruggen%2Fnativescript-star-printer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EddyVerbruggen","download_url":"https://codeload.github.com/EddyVerbruggen/nativescript-star-printer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975328,"owners_count":21192210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cashdrawer","nativescript","nativescript-plugin","printer","star","stario"],"created_at":"2024-10-01T07:59:29.109Z","updated_at":"2025-04-14T23:13:25.124Z","avatar_url":"https://github.com/EddyVerbruggen.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NativeScript Star Printer\n\n[![NPM version][npm-image]][npm-url]\n[![Downloads][downloads-image]][npm-url]\n[![Twitter Follow][twitter-image]][twitter-url]\n\n[build-status]:https://travis-ci.org/EddyVerbruggen/nativescript-star-printer.svg?branch=master\n[build-url]:https://travis-ci.org/EddyVerbruggen/nativescript-star-printer\n[npm-image]:http://img.shields.io/npm/v/nativescript-star-printer.svg\n[npm-url]:https://npmjs.org/package/nativescript-star-printer\n[downloads-image]:http://img.shields.io/npm/dm/nativescript-star-printer.svg\n[twitter-image]:https://img.shields.io/twitter/follow/eddyverbruggen.svg?style=social\u0026label=Follow%20me\n[twitter-url]:https://twitter.com/eddyverbruggen\n\n\u003cimg src=\"https://github.com/EddyVerbruggen/nativescript-star-printer/raw/master/media/demo-app.gif\" width=\"328px\" height=\"577px\" /\u003e\n\n_That's [the demo app](https://github.com/EddyVerbruggen/nativescript-star-printer/tree/master/demo) in action, printing on a Star Micronics TSP650II_\n\n## Installation\n\n\u003e For NativeScript 7+, please use plugin version 4+ \n\n```bash\ntns plugin add nativescript-star-printer\n```\n\n## API\n\n### requiring / importing the plugin\nAll examples below assume you're using TypeScript, but here's how to require the plugin with plain old JS as well:\n\n#### JavaScript\n```js\nvar StarPrinterPlugin = require(\"nativescript-star-printer\");\nvar starPrinter = new StarPrinterPlugin.StarPrinter();\n```\n\n#### TypeScript\n```typescript\nimport { StarPrinter, SPPrinter, SPCommands } from \"nativescript-star-printer\";\n\nexport Class MyPrintingClass {\n  private starPrinter: StarPrinter;\n  \n  constructor() {\n    this.starPrinter = new StarPrinter();\n  }\n}\n```\n\n### `searchPrinters`\nIf you're searching for a Bluetooth printer, enable Bluetooth in the device settings\nand pair/connect the printer. Then do:\n\n```typescript\nthis.starPrinter.searchPrinters().then(\n    (printers: Array\u003cSPPrinter\u003e) =\u003e {\n      console.log(`Found ${printers.length} printers`);\n    }, (err: string) =\u003e {\n      console.log(`Search printers error: ${err}`);\n    });\n```\n\nThe most useful property on the `SPPrinter` class is the `portName` which you will need\nin other API methods.\n\nThe only other property is `modelName`.\n\n### `connect`\nOnce you know the printer port name, you can connect to it.\n\n\u003e Note that there's no need to connect if you want to print as the print function does this automatically.\n\n```typescript\nthis.starPrinter.connect({\n  portName: thePortName\n}).then((result: SPPrinterStatusResult) =\u003e console.log(\"Connected: \" + result.connected));\n```\n\n### `getPrinterStatus`\nAfter connecting to a printer, you can use this method to poll for the 'online' and 'paper' statuses.\n\n```typescript\nthis.starPrinter.getPrinterStatus({\n  portName: this.lastConnectedPrinterPort\n}).then(result =\u003e {\n  const online: boolean = result.online;\n  const onlineStatus: PrinterOnlineStatus = result.onlineStatus;\n  const paperStatus: PrinterPaperStatus = result.paperStatus;\n});\n```\n\n### `print`\nOnce you've got the port of the printer you want to print to, just do:\n\n```typescript\nthis.starPrinter.print({\n  portName: this.selectedPrinterPort,\n  commands: commands\n});\n```\n\nSo what are those `commands`? Let's recreate the fake receipt below to answer that (see the TypeScript definition for all options):\n\n\u003cimg src=\"https://github.com/EddyVerbruggen/nativescript-star-printer/raw/master/media/demo-app-receipt-with-barcode.jpg\" width=\"500px\" /\u003e\n\n```typescript\nconst image = ImageSource.fromFile(\"~/res/mww-logo.png\");\n\n// Note that a standard 3 inch roll is 48 characters wide - we use that knowledge for our \"columns\"\nlet commands = new SPCommands()\n    .image(\n        image,\n        true, // diffuse\n        true // align center (set to 'false' to align left)\n     )\n    // alternatively, you can use imagePositioned for a bit more control (on Android this behaves the same as 'image' though)\n    .imagePositioned(\n        image,\n        80, // width\n        20, // position\n        true, // both scale\n        true, // diffuse\n        true // align center (set to 'false' to align left)\n     )\n    .alignCenter()\n    .text(\"My Awesome Boutique\").newLine()\n    .text(\"In a shop near you\").newLine()\n    .setFont(\"smaller\")\n    .text(\"Planet Earth\").newLine()\n    .setFont(\"default\")\n    .newLine()\n    .text(\"Date: 11/11/2017                   Time: 3:15 PM\")\n    .horizontalLine() // you can pass in the character and the nr of characters (use 48 for a 3\" roll, 42 for a smaller one)\n    .newLine()\n    .textBold(\"SKU           Description                  Total\").newLine()\n    .text(\"300678566     Plain White Tee             €10.99\").newLine()\n    .text(\"300692003     Black Dénim                 €29.99\").newLine()\n    .text(\"300651148     Blue Denim                  €29.99\").newLine()\n    .newLine()\n    .newLine()\n    .barcode({\n      type: \"Code128\",\n      value: \"12345678\",\n      width: \"large\",\n      height: 60,\n      appendEncodedValue: false\n    })\n    .newLine()\n    .cutPaper();\n\nthis.starPrinter.print({\n  portName: this.selectedPrinterPort,\n  commands: commands\n});\n```\n\n### `openCashDrawer`\nIn case a cash drawer is connected via the UTP (network) connector of the Star printer,\nyou can open the drawer from your code!\n\n```typescript\nthis.starPrinter.openCashDrawer({\n  portName: this.selectedPrinterPort\n});\n```\n\n## iOS runtime permission reason\niOS 10+ requires a permission popup when connecting (the first) time to a Bluetooth peripheral explaining *why* it needs to connect.\n\nYou can provide your own reason by adding something like this to `app/App_Resources/ios/Info.plist`:\n\n```xml\n  \u003ckey\u003eNSBluetoothPeripheralUsageDescription\u003c/key\u003e\n  \u003cstring\u003eMy reason justifying fooling around with your Bluetooth\u003c/string\u003e\n```\n\n_To not crash your app in case you forgot to provide the reason this plugin adds an empty reason to the `.plist` during build. This value gets overridden by anything you specified yourself. You're welcome._\n\n## Known limitations\nOn iOS you want to run this on a real device.\n\n\n## Future work\nPossibly add more `print` formatting options.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feddyverbruggen%2Fnativescript-star-printer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feddyverbruggen%2Fnativescript-star-printer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feddyverbruggen%2Fnativescript-star-printer/lists"}