bpac-js
Version:
High level API for interacting with the Brother BPAC SDK
249 lines (246 loc) • 9.24 kB
TypeScript
type TemplateData = {
[key: string]: string | Date;
};
type Constructor = {
templatePath: string;
exportDir?: string;
printer?: string;
};
type PrintOptions = {
copies?: number;
printName?: string;
};
declare enum PrintOptionFlag {
autoCut = 1,
cutPause = 1,
cutMark = 2,
halfCut = 512,
chainPrint = 1024,
tailCut = 2048,
specialTape = 524288,
cutAtEnd = 67108864,
noCut = 268435456,
mirroring = 4,
quality = 65536,
highSpeed = 16777216,
highResolution = 33554432,
color = 8,
mono = 268435456
}
type StartPrintOptions = {
[key in keyof typeof PrintOptionFlag]?: boolean;
};
type FitPage = {
fitPage?: boolean;
};
type PrintConfig = PrintOptions & StartPrintOptions & FitPage;
type ImageOptions = {
width?: number;
height?: number;
};
interface PrinterStatus {
printerName: string | null;
online: boolean | null;
supported: boolean | null;
errorCode: number | null;
errorString: string | null;
currentMedia: string[] | null;
supportedMedia: string[] | null;
}
declare class BrotherSdk {
#private;
templatePath: string;
printer?: string;
exportDir?: string;
/**
* **BPAC-JS Class Object**
*
* Create a new instance of this class to interact with the Brother SDK
* in JavaScript. This object facilitates communication and integration
* with the SDK functionalities.
* @param {Constructor} object
* @param {String} object.templatePath
* Specifies the path to the template file
* - Win path: "C:\\\path\\\to\\\your\\\template.lbx"
* - Unix path: "/home/templates/template.lbx"
* - UNC path: "\\\server\share\template.lbx"
* - Remote URL: "https://yourserver.com/templates/label.lbx"
* @param {String} [object.exportDir = ""]
* The path for exporting generated assets.
* - Win path: "C:\\\path\\\to\\\your\\\"
* - Unix path: "/home/templates/"
* @param {String} [object.printer = undefined]
* The name of the printer used for printing. Specify the printer name, not the path.
* - Example: "Brother QL-820NWB"
* @example
* //use the static method getPrinterList() to obtain a list of installed printers.
* BrotherSdk.getPrinterList()
*/
constructor({ templatePath, exportDir, printer }: Constructor);
getPrinterStatus(): Promise<PrinterStatus>;
/**
* **Method for Printing a Label (Single or Batch)**
*
* Asynchronously prints one or multiple labels using the specified configurations.
*
* This function supports both **single-object** and **batch printing**.
* - If a single `TemplateData` object is passed, it prints one label.
* - If an array of `TemplateData` objects is passed, it prints multiple labels in sequence.
*
* Note: Flags are valid only with those models that support each function.
* The setting is invalid with models that do not support a function,
* even if a flag is set.
*
* @param {TemplateData | TemplateData[]} data
* A **single object** or **an array of objects** containing key-value pairs.
* Each key represents an object ID, and the corresponding value is the text
* to be set on that object.
*
* @param {PrintConfig} [config]
* Optional configuration object.
*
* @param {Number} [config.copies = 1]
* Number of copies to print.
*
* @param {String} [config.printName = "BPAC-Document"]
* Print document name.
*
* @param {boolean} [config.autoCut = false]
* Auto cut is applied.
*
* @param {boolean} [config.cutPause = false]
* Pause to cut is applied. Valid only with models not supporting the auto cut function.
*
* @param {boolean} [config.cutMark = false]
* Cut mark is inserted. Valid only with models not supporting the auto cut function.
*
* @param {boolean} [config.halfCut = false]
* Executes half cut.
*
* @param {boolean} [config.chainPrint = false]
* Continuous printing is performed. The final label is not cut, but when the next
* labels are output, the preceding blank is cut in line with the cut option setting.
*
* @param {boolean} [config.tailCut = false]
* Whenever a label is output, the trailing end of the form is forcibly cut to
* leave a leading blank for the next label output.
*
* @param {boolean} [config.specialTape = false]
* No cutting is performed when printing on special tape.
* Valid only with PT-2430PC.
*
* @param {boolean} [config.cutAtEnd = false]
* "Cut at end" is performed.
*
* @param {boolean} [config.noCut = false]
* No cutting is performed. Valid only with models supporting cut functions.
*
* @param {boolean} [config.mirroring = false]
* Executes mirror printing.
*
* @param {boolean} [config.quality = false]
* Fine-quality printing is performed.
*
* @param {boolean} [config.highSpeed = false]
* High-speed printing is performed.
*
* @param {boolean} [config.highResolution = false]
* High-resolution printing is performed.
*
* @param {boolean} [config.color = false]
* Color printing is performed.
*
* @param {boolean} [config.mono = false]
* Monochrome printing is performed. Valid only with models supporting
* the color printing function.
*
* @param {boolean} [config.fitPage = false]
* Specify whether to adjust the size and position of objects in the template in accordance
* with layout changes resulting from media changes. If set to true, adjustments
* will be made; otherwise, if set to false or undefined, no adjustments will be applied.
*
* @returns {Promise<boolean>}
* Resolves to `true` when printing completes successfully.
*
* **Usage Examples**
*
* **Single Print**
* ```typescript
* await printer.print({ text: "Label 1", barcode: "12345" }, { copies: 2 });
* ```
*
* **Batch Print**
* ```typescript
* await printer.print([
* { text: "Label 1", barcode: "12345" },
* { text: "Label 2", barcode: "67890" }
* ], { copies: 2 });
* ```
*/
print(data: TemplateData | TemplateData[], config?: PrintConfig): Promise<boolean>;
/**
* **Method For Retrieving The Label's Image Data**
*
* Asynchronously retrieves and returns Base64-encoded image data for a label.
*
* @param {TemplateData} data
* An object containing key-value pairs, where each key represents an object ID,
* and the corresponding value is the text to be set on that object.
* @param {ImageOptions} options
* Optional
* @param {string} options.height
* If the vertical size (dpi) of the image to be acquired is specified as 0, it
* becomes a size that maintains the aspect ratio based on width.
* @param {string} options.width
* Horizontal size (dpi) of the image to be acquired. If 0 is specified,
* it becomes a size that maintains the aspect ratio based on height.
* @returns {Promise<string>}
* A promise that resolves to a Base64 encoded string representing the image data.
*/
getImageData(data: TemplateData, options: ImageOptions): Promise<string>;
/**
* **Retrieve The Printer's Name**
*
* Asynchronously retrieves the printers name for the current context.
*
* @returns {Promise<string>}
* A promise that resolves with the name of the printer.
*
*/
getPrinterName(): Promise<string>;
/**
* **Export Label To File**
*
* Asynchronously populate & export a copy of the file in various formats.
*
* @param {Object} data
* An object containing key-value pairs, where each key represents
* an object ID, and the corresponding value is the text to be set on that object.
* @param {String} [filePathOrFileName = ""]
* Provide a file name or absolute path.
* - e.g. = "myLabel.lbx" will be stored in the exportDir path provided.
* - e.g. = "C:/Templates/myLabel.lbx" will override the exportDir.
* - Supported file types = .lbx | .lbl | .lbi | .bmp | .paf
* @param {Number} [resolution = 0]
* Provide a resolution in dpi used for the conversion into bitmap format.
* Specifies the resolution of the output device.
* (Screen: 72 or 96; output to SC-2000: 600)
* If a value of 0 is specified, the printer resolution is used.
*
* The resolution param is only valid for .lbi and .bmp extensions.
*/
export(data: TemplateData, filePathOrFileName: string, resolution: number): Promise<boolean>;
/**
* **Get List Of Installed Printers**
*
* asynchronously retrieves the list of installed printers compatible with the bpac SDK.
*
* @returns {Promise<string[]>}
* a promise that resolves to an array of installed printers
* compatible with the 'bpac' SDK.
*
*/
static getPrinterList(): Promise<string[]>;
static printerIsReady(timeout?: number): Promise<void>;
}
export { BrotherSdk, BrotherSdk as default };