UNPKG

@mmote/niimbluelib

Version:

Library for the communication with NIIMBOT printers

73 lines (72 loc) 2.6 kB
import { EncodedImage } from "../image_encoder"; import { LabelType } from "../packets"; import { Abstraction } from "../packets/abstraction"; /** * Print options for print tasks. * @category Print tasks */ export type PrintOptions = { /** Printer label type */ labelType: LabelType; /** Print density */ density: number; /** How many pages will be printed */ totalPages: number; /** Used in {@link AbstractPrintTask.waitForFinished} where status is received by polling */ statusPollIntervalMs: number; /** Used in {@link AbstractPrintTask.waitForFinished} */ statusTimeoutMs: number; /** Used in {@link AbstractPrintTask.printPage} */ pageTimeoutMs: number; /** Print speed (it called "printing mode" with "print for clarity" and "print for speed" variants on original app). * Supported in D110MV4PrintTask */ speed: 0 | 1; /** Print temperature for multicolor paper. * Supported in B1PrintTask and D110MV4PrintTask */ color: number; }; /** * Different printer models have different print algorithms. Print task defines this algorithm. * * @example * ```ts * const quantity = 1; * * const printTask = client.abstraction.newPrintTask("D110", { * totalPages: quantity * }); * * try { * await printTask.printInit(); * await printTask.printPage(encodedImage, quantity); // encode your canvas with ImageEncoder.encodeCanvas * await printTask.waitForPageFinished(); * await printTask.waitForFinished(); * } catch (e) { * alert(e); * } finally { * await client.abstraction.printEnd(); * } * ``` * * @category Print tasks **/ export declare abstract class AbstractPrintTask { protected abstraction: Abstraction; protected printOptions: PrintOptions; protected pagesPrinted: number; constructor(abstraction: Abstraction, printOptions?: Partial<PrintOptions>); /** Check added pages not does not exceed {@link pagesPrinted} */ protected checkAddPage(quantity: number): void; /** Prepare print (set label type, density, print start, ...) */ abstract printInit(): Promise<void>; /** Print image with a specified number of copies */ abstract printPage(image: EncodedImage, quantity?: number): Promise<void>; /** Wait for page print is finished */ waitForPageFinished(): Promise<void>; /** Wait for all print is finished */ abstract waitForFinished(): Promise<void>; /** Printer's printhead resolution in pixels */ protected printheadPixels(): number | undefined; /** End print, cleanup */ printEnd(): Promise<boolean>; }