electron-zebra is a small utility program that can handle print requests via a rest api.
It serves the API Endpoint at the port 65533
Get the latest stable release from here and install.
In order to build on Windows systems, you have to install windows-build-tools
$ npm install -g --production windows-build-tools
$ git clone https://github.com/PlatinMarket/electron-zebra.git
$ yarn
OR
$ npm install
Build and execute the electron app in development mode.
$ yarn dev
Use to rebuild modules for electron. This command is automatically called in postinstall
.
$ yarn dev:rebuild
Build the installer without publishing to github.
$ yarn dist:build
Build the installer and release it through github. For this option you need to configurate the package.json
$ yarn dist:publish
Configurate package.json
for auto update releases.
{
"name": "<APP_NAME>",
...
"repository": {
"type": "git",
"url": "<REPO_URL>"
},
...
"build": {
"appId": "com.electron.<APP_NAME>",
"productName": "<APP_DISPLAY_NAME>",
...
"publish": {
"provider": "github",
}
}
}
- Create a public GitHub repo for your project. And change the
repository.url
in thepackage.json
with your repo URL. - Create a new personal access token with the repo scope from here.
- Set
GH_TOKEN
environment variable with the token you've generated. - You're ready to publish.
$ yarn dist:publish
Alternatively you can also define the GH_TOKEN
just for the current shell session like the example below.
$ export GH_TOKEN='########################################'
$ yarn dist:publish
You can also publish the generated files through github release manually.
- Build your app with
yarn dist:build
. - Go to GitHub Releases in your repo.
- Draft a new release.
- Enter Tag Name. ex. v1.0.x (1.0.x builded app version)
- Enter Release Title.
- Enter Description.
- Upload the generated files in the ./distribution
- Upload latest.yml.
- Upload APPNAME-setup.exe.
- Upload APPNAME-setup.exe.blockmap.
- Publish Release.
Get the default device's index and all the supported devices attached to the server system.
REQUEST
METHOD: GET
URL: <ip>:65533
RESPONSE
BODY: {
selected: <index> | -1, // Default handler's index or -1 if not present.
devices: <Device>[ ... ] // Device list
}
cURL Example
$ curl -i -H "Accept: application/json" <ip>:65533
> HTTP/1.1 200 OK
> X-Powered-By: Express
> Access-Control-Allow-Origin: *
> Content-Type: application/json; charset=utf-8
> Content-Length: 180
> ETag: W/"b4-NbSK2aHRpR5gJagyYDFOO681tRY"
> Date: Sat, 19 Oct 2019 10:09:27 GMT
> Connection: keep-alive
> {
"selected": -1,
"devices": [
{
"locationId": 0,
"vendorId": 2655,
"productId": 211,
"deviceName": "ZTC GC420t (EPL)",
"manufacturer": "Zebra",
"serialNumber": "54J154102172",
"deviceAddress": 14
}
]
}
Set the default device to handle print requests that sent without a target device.
REQUEST
METHOD: POST
URL: <ip>:65533
HEADERS:
Content-type: "x-application/zpl"
x-default-printer: <index>
RESPONSE
200 OK | 500 Internal Error | 400 Bad Request
cURL Example
curl -i -H "Content-Type: x-application/zpl" -H "x-default-printer: 0" -X POST <ip>:65533
> HTTP/1.1 200 OK
> X-Powered-By: Express
> Access-Control-Allow-Origin: *
> Content-Type: text/html; charset=utf-8
> Content-Length: 32
> ETag: W/"20-ruIGTBxF9UD8IqO8YTC8bpDmrQo"
> Date: Sat, 19 Oct 2019 10:30:12 GMT
> Connection: keep-alive
> "Default printer succesfully set."
Send print request to the default device.
REQUEST
METHOD: POST
URL: <ip>:65533
HEADERS:
Content-type: "x-application/zpl"
BODY:
<zpl code>
RESPONSE
200 OK | 500 Internal Error | 400 Bad Request
cURL Example
$ curl -i -H "Content-Type: x-application/zpl" --data "^XA^CF0,30^FO220,115^FD PRINT REQUEST ^FS^XZ" -X POST <ip>:65533
> HTTP/1.1 200 OK
> X-Powered-By: Express
> Access-Control-Allow-Origin: *
> Date: Sat, 19 Oct 2019 10:31:06 GMT
> Connection: keep-alive
> Content-Length: 0
Send print request to targeted device.
REQUEST
METHOD: POST
URL: <ip>:65533
HEADERS:
Content-type: "x-application/zpl"
x-printer: <index>
BODY:
<zpl code>
RESPONSE
200 OK | 500 Internal Error | 400 Bad Request
cURL Example
$ curl -i -H "Content-Type: x-application/zpl" -H "x-printer: 0" --data "^XA^CF0,30^FO220,115^FD PRINT REQUEST ^FS^XZ" -X POST <ip>:65533
> HTTP/1.1 200 OK
> X-Powered-By: Express
> Access-Control-Allow-Origin: *
> Date: Sat, 19 Oct 2019 10:31:06 GMT
> Connection: keep-alive
> Content-Length: 0
cURL Example: concurrent print request to the default device and a targeted device.
$ curl -i -H "Content-Type: x-application/zpl" -H "x-printer: 0" --data "^XA^CF0,30^FO220,115^FD CONCURRENT PRINT REQUEST 1 ^FS^FO220,155^FD CONCURRENT PRINT REQUEST 1 ^FS^FO220,195^FD CONCURRENT PRINT REQUEST 1 ^FS^XZ" -X POST http://localhost:65533 & curl -i -H "Content-Type: x-application/zpl" --data "^XA^CF0,30^FO220,115^FD CONCURRENT PRINT REQUEST 2 ^FS^FO220,155^FD CONCURRENT PRINT REQUEST 2 ^FS^FO220,195^FD CONCURRENT PRINT REQUEST 2 ^FS^XZ" -X POST http://localhost:65533
> HTTP/1.1 200 OK
> X-Powered-By: Express
> Access-Control-Allow-Origin: *
> Date: Sat, 19 Oct 2019 11:20:31 GMT
> Connection: keep-alive
> Content-Length: 0
> HTTP/1.1 200 OK
> X-Powered-By: Express
> Access-Control-Allow-Origin: *
> Date: Sat, 19 Oct 2019 11:20:31 GMT
> Connection: keep-alive
> Content-Length: 0