Skip to content

Commit

Permalink
refactor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yeasir01 committed Feb 17, 2024
1 parent ceeb5eb commit eecc878
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BrotherBrotherSdk } from "bpac-js";
```

### CDN
Include import at the top of your script file. And set type to module in .html (requires live-server or equivalent).
Include import at the top of your script file, and set script type to module in .html (load using live-server or equivalent).

```javascript
import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@{version#}/dist/index.js";
Expand All @@ -31,17 +31,16 @@ import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@{version#}/dist/ind
### Get Printer Name
```javascript
// script.js file
import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.js";

const getNameBtn = document.getElementById("get-name-btn");

const tag = new BrotherSdk({
templatePath: "C:/Templates/shoe-template.lbx",
exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/",
printer: "Brother QL-820NWB"
});

// Returns the printer associated with the template in string format
const getName = async () => {
const getPrinter = async () => {
try {
const printer = await tag.getPrinterName();
console.log({printer}) // Output: {printer: "Brother QL-820NWB"}
Expand All @@ -50,18 +49,16 @@ const getName = async () => {
}
};

getNameBtn.addEventListener("click", getName);
getNameBtn.addEventListener("click", getPrinter);

```

### Get List Of Printers
```javascript
// script.js file
import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.js";

const getNameBtn = document.getElementById("get-name-btn");

const getNames = async () => {
const getPrinters = async () => {
try {
const printers = await BrotherSdk.getPrinterList();
console.log({printers}) // Output: {printers: ["Brother QL-820NWB", "Brother PT-9800PCN"]}
Expand All @@ -70,20 +67,19 @@ const getNames = async () => {
}
};

getNameBtn.addEventListener("click", getNames);
getNameBtn.addEventListener("click", getPrinters);

```

### Print
```javascript
// script.js file
import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.js";

const printBtn = document.getElementById("print-btn");

const tag = new BrotherSdk({
templatePath: "C:/Templates/shoe-template.lbx",
exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/",
printer: "Brother QL-820NWB"
});

// The keys and values must match the objects/types in the template file.
Expand All @@ -101,7 +97,7 @@ const options = {
highResolution: true
}

const sendToPrinter = async () => {
const handlePrint = async () => {
try {
const isPrinted = await tag.print(data, options);
console.log({isPrinted})
Expand All @@ -110,21 +106,20 @@ const sendToPrinter = async () => {
}
};

printBtn.addEventListener("click", sendToPrinter);
printBtn.addEventListener("click", handlePrint);

```

### Preview
```javascript
// script.js file
import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.mjs";

const previewBtn = document.getElementById("preview-btn");
const imgOutput = document.getElementById("img")

const tag = new BrotherSdk({
templatePath: "C:/Templates/shoe-template.lbx",
exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/",
printer: "Brother QL-820NWB"
});

// The keys and values must match the objects/types in the template file.
Expand All @@ -140,7 +135,7 @@ const options = {
height: 0 // Optional - Defaults to 0
}

const previewImage = async () => {
const handlePreview = async () => {
try {
const data = await tag.getImageData(data, options); //image data
imgOutput.src = data;
Expand All @@ -149,20 +144,19 @@ const previewImage = async () => {
}
};

previewBtn.addEventListener("click", previewImage);
previewBtn.addEventListener("click", handlePreview);

```

### Export
```javascript
// script.js file
import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.mjs";

const exp = document.getElementById("export-btn");

const tag = new BrotherSdk({
templatePath: "C:/Templates/shoe-template.lbx",
exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/",
printer: "Brother QL-820NWB"
});

// The keys and values must match the objects/types in the template file.
Expand All @@ -173,7 +167,7 @@ const data = {
date: new Date("2024-1-20"),
};

const exportFile = async () => {
const handleExport = async () => {
try {
// Docs >> Options >> Supported Ext Types - for support file types
const success = await tag.export(data, "Air-Force.bmp", 300);
Expand All @@ -183,6 +177,6 @@ const exportFile = async () => {
}
};

exp.addEventListener("click", exportFile);
exp.addEventListener("click", handleExport);

```

0 comments on commit eecc878

Please sign in to comment.