JSPrintManager
repository·master·Indexed 43 days ago
https://github.com/neodynamic/jsprintmanagerA client-side printing and scanning solution that enables web applications to perform silent printing, raw command printing (ZPL, EPL, ESC/POS), and document scanning via JavaScript. It bridges web browsers to local hardware, supporting PDF, DOCX, XLSX, and image printing, as well as bidirectional communication over Serial, TCP/IP, Bluetooth, USB, HID, and IPP.
What's inside JSPrintManager
- JSPrintManager is a client-side printing and scanning solution that uses a combination of a JavaScript library and a lightweight native client application. It allows web applications to send raw data, text, native commands, and various file formats (PDF, TIFF, TXT, DOC, XLS, JPG, PNG, etc.) directly to printers installed on the client machine without displaying a print dialog box. It is compatible with any web platform (ASP.NET, PHP, Django, etc.) and any modern JavaScript framework (Angular, React, Vue, etc.).
How JSPrintManager components work together
masterJSPrintManager operates using two primary components:
- The Website component (JSPrintManager.js): A JavaScript object integrated into your website used to generate "Client Print Jobs."
- The Client-side component: A lightweight native application installed on the client machine (Windows, Linux, macOS, or Raspberry Pi) that receives and processes the "Client Print Jobs" generated by the JavaScript object.
This architecture enables silent printing and scanning from sandboxed environments like web browsers.
Use JSPrintManager with React, Angular, or Vue
masterJSPrintManager provides sample implementations for popular modern frameworks:
- React: See the JSPrintManager Online Demo source code.
- Angular: Use the JSPrintManager-Angular sample repository.
- Vue: Use the JSPrintManager-Vue sample repository.
- Other Frameworks: For any other framework, use plain JavaScript code as documented in the official articles.
Manage printers and monitor print jobs
masterJSPrintManager provides capabilities to interact with the local printing environment:
- Printer Detection: Detect when a printer is added, created, updated, or removed.
- Printer Types: Distinguish between virtual and real-physical printers.
- Job Monitoring: Trace the status of print jobs from JavaScript.
- Mobile/Sandboxed Support: Print raw commands and PDF files from iOS, Android, ChromeOS, and other sandboxed environments.
Communicate via Serial Port (BIDI)
masterYou can use JSPrintManager to perform bidirectional (BIDI) communication over serial ports, allowing you to both send/write and receive/read data from serial devices using JavaScript.Print known file formats (PDF, DOCX, XLSX, Images)
masterYou can perform silent printing of various file formats with advanced settings from JavaScript:
- PDF: Supports tray selection, paper size, rotation, and page range settings.
- MS Word (*.doc, *.docx): Supports duplex, reverse, and page range settings.
- MS Excel (*.xls, *.xlsx): Supports page range settings.
- Images (*.jpg, *.png): Supports custom location, size, and page orientation settings.
- HTML/CSS: Print HTML content directly to the client printer, including silent mode (without print dialog).
Scan documents and images
masterJSPrintManager supports web scanning, allowing you to scan documents and images directly from a browser using connected scanning hardware.Print RAW printer commands (ZPL, EPL, ESC/POS, etc.)
masterJSPrintManager allows you to send raw printer commands directly to various printer languages. This is useful for label printers and receipt printers that require specific command sets. Supported languages include:
- Zebra: ZPL and EPL commands (including Unicode UTF8 support).
- Epson: ESC/POS commands (can be generated using
JSESCPOSBuilder). - Intermec: IPL commands.
- BOCA: FGL commands.
- Datamax: DPL commands.
- Godex: EZPL commands.
You can print these commands from Web APIs, WebServices, and both remote and local files.
Initialize JSPrintManager and establish WebSocket connection
masterTo use JSPrintManager, you must start the library and connect to the local WebSocket server. You can enable automatic reconnection using
JSPM.JSPrintManager.auto_reconnect = true.Use
JSPM.JSPrintManager.start(useSSL, host, port)to initiate the connection.It is common practice to assign your application instance to
JSPM.JSPrintManager.MainAppso that the library's WebSocket event handlers can call back into your application logic.JSPM.JSPrintManager.auto_reconnect = true; JSPM.JSPrintManager.start(true, 'localhost', 29443); // Link your app instance to handle callbacks JSPM.JSPrintManager.MainApp = this;Get printer and device information
masterJSPrintManager provides APIs to query the state and capabilities of client hardware:
- Printers Info: Retrieve a list of installed printers and details such as
DPI Resolution,PortName,Is Connected,Is Shared,Is Local,Is Network, and whether it is aVirtual or Real/Physical printer. You can also retrieve supportedPapersandtrays/bins. - Printers Watcher (Windows only): Detect when printers are added, removed, or modified.
- Print Jobs Status: Trace the status of print jobs, including completion and number of pages printed.
- Bluetooth Devices Info: Get a list of available Bluetooth devices including
Name,Address,Class of Device,Connected,Remembered, andAuthenticatedstatus.
- Printers Info: Retrieve a list of installed printers and details such as
Supported Printing and Scanning Features
masterJSPrintManager supports a wide range of capabilities:
Printing
- Raw Data Printing: Send commands for EPSON ESC/POS, HP PCL, PostScript, Zebra ZPL, and Eltron EPL. Supports shipping labels (UPS, FedEx, etc.) and PRN files.
- Advanced PDF Printing: Silent printing with settings for Tray Name, Paper Size, Rotation, Pages Range, Duplex, and Password-protection.
- File Printing: Native support for PDF, TXT, PNG, JPG, and BMP. Support for DOC/x, XLS/x, and Multipage TIFF (requires external software like MS Word, Excel, or LibreOffice).
- Advanced DOC/XLS Printing: Silent printing for Word and Excel files (Windows only, requires MS Office 97+).
- Tray & Paper Size: Specify Tray Name and Paper Size for PDF, JPEG, PNG, BMP, and TXT files (requires printer driver support).
Scanning & Imaging
- Web Scan: Scan via TWAIN/WIA/SANE-compatible devices with settings for DPI, Pixel Mode (Grayscale, Color, B&W), and Output Format (JPG, PNG, TIF, PDF). Duplex/ADF supported on Windows.
- Video Snapshots: Capture snapshots from video devices in Grayscale, Color, JPG, PNG, or PDF formats.
Bidirectional (BIDI) Communication
- Serial: RS-232, COM, and TTY ports.
- TCP/IP: Send/Receive data to any TCP Address and port (must be in the client's allow list).
- Bluetooth: Send/Receive data to BT Address and Channel (must be in the client's allow list).
- USB: Send/Receive data to any USB device.
- HID: Send/Receive data to any HID device.
- IPP: Send/Request IPP JSON messages to IPP URI devices (must be in the client's allow list).
Handle JSPrintManager WebSocket events
masterThe
JSPM.JSPrintManager.WSobject provides hooks to respond to the lifecycle of the WebSocket connection. You can monitor connection status, errors, and closures.Available event handlers:
onOpen: Triggered when the connection is successfully established.onError: Triggered when a WebSocket error occurs.onStatusChanged: Triggered when the connection status changes.onClose: Triggered when the connection is closed.
Use
JSPM.WSStatusto map the numericWS.statusto a human-readable string (e.g., "Open").JSPM.JSPrintManager.WS.onOpen = function() { console.log("Connected!"); }; JSPM.JSPrintManager.WS.onError = function (e) { console.log("WebSocket Error:", e); }; JSPM.JSPrintManager.WS.onStatusChanged = function() { const status = JSPM.WSStatus[JSPM.JSPrintManager.WS.status]; console.log("Status changed to:", status); }; JSPM.JSPrintManager.WS.onClose = function() { console.log("Connection closed"); };