Ng111printer is a comprehensive package designed to simplify thermal printing in Angular projects. The development team encountered challenges in finding a direct way to print from Angular, prompting them to create a solution. The package includes a simple driver with an API, the WIN_PRINTER_CONECTOR service, making installation hassle-free.
- Compatible with any installed printer on Windows.
- Uninstallation is straightforward through the Windows Control Panel under "win-printer-connector."
- Ng111printer detects all printers installed on your PC.
- Works for projects running on localhost or where the server side matches the printer installation.
Download and install the corresponding versions from this link.
Ng111printer Version | WIN_PRINTER_CONECTOR Version |
---|---|
1.0.15 | 1.0.6 |
1.0.13 | 1.0.3 |
1.0.11 | 1.0.2 |
1.0.10 | 1.0.2 |
1.0.9 | 1.0.2 |
1.0.7 | 1.0.2 |
1.0.6 | 1.0.2 |
- Open the setup file.
- Start the service either by restarting your PC or accessing the Services app, finding the service named WIN_PRINTER_CONECTOR, and right-clicking to start.
- Access the Windows Control Panel.
- Find the program WIN_PRINTER_CONECTORvX.X.X.
- Click uninstall.
-
Install the package using npm in your Angular project:
npm install ng111printer
-
Import the library into the component where printing is needed:
import * as Ng111printer from 'ng111printer';
-
Initialize the
ConectorPrinterService
in the component's constructor:constructor( private conectorPrinterService: Ng111printer.ConectorPrinterService ) { }
-
Request a list of printers:
this.conectorPrinterService.solicitarListaImpresoras().then((printersList) => { let list = printersList.mensaje.split(','); // Store the list in a global variable this.printers = list; }).catch((error) => { console.log("Error in the printers request:", error); return; });
-
Configure the printer:
let printerConfiguration: Ng111printer.ConfImpresoraBtec = { nombre: 'YourPrinterName', // Replace with your printer name altoPapel: 0, // Use 0 to ignore anchoPapel: 0, // Use 0 to ignore margenes: 0 // Use 0 to ignore };
-
Create the template structure:
let ticketTemplate = [ // Elements like images, text, QR codes, etc. ];
-
Construct the print object:
let print: Ng111printer.ImpresionBtec = { accion: Ng111printer.AccionImpresion.imprimir, confImpresora: printerConfiguration, plantillas: ticketTemplate, copias: 1 };
-
Send the print object to the printer:
this.conectorPrinterService.imprimir(print).then((resp) => { console.log("Finished print", resp); }).catch((error) => { console.log("Error printing.", error); });
Here is a more detailed example:
// ... (Previous imports and setup)
// Function to print an example
imprimirTicket() {
// Validation for selected printer
if (this.impresoraSeleccionada === '') {
console.log('Seleccione una impresora de la lista');
return;
}
// Object to store the printer configuration
let configuracionImpresora: Ng111printer.ConfImpresoraBtec = {
nombre: this.impresoraSeleccionada,
altoPapel: 0,
anchoPapel: 0,
margenes: 0
};
// Base64 image to print
let bitmapLogo = 'replace with your image in base64';
// Create styles for the image
let estilosLogo: Ng111printer.EstilosImagen = new Ng111printer.EstilosImagen(
Ng111printer.AlineacionBtec.centro, -1, 100, -1
);
// Variable to create the image with the ng111printer.Imagen class
let logo: Ng111printer.Imagen = new Ng111printer.Imagen(bitmapLogo, estilosLogo);
// Styles for Qr code
let estilosQr: Ng111printer.EstilosQr = new Ng111printer.EstilosQr(undefined, Ng111printer.AlineacionBtec.centro);
// Styles for the left side text on the TextosExtremos content
let estilosIzqLO1: Ng111printer.EstilosTexto1 = new Ng111printer.EstilosTexto1(
Ng111printer.TipografiaBtec.consolas, Ng111printer.TamanioBtec.regular,
Ng111printer.AlineacionBtec.izq, Ng111printer.TipoBtec.regular
);
// Styles for the right side text on the TextosExtremos content
let estilosDerLO1: Ng111printer.EstilosTexto2 = new Ng111printer.EstilosTexto2(
Ng111printer.TipografiaBtec.consolas, undefined, Ng111printer.AlineacionBtec.der
);
// Template with the elements to print
let plantillaTicket = [
// 111BTEC logo
logo,
// Ticket title
new Ng111printer.Texto(
'IMPRESIÓN PLUGIN Ng111Printer',
new Ng111printer.EstilosTexto(
Ng111printer.TipografiaBtec.lucidaConsole, Ng111printer.TamanioBtec.regular,
Ng111printer.AlineacionBtec.centro, Ng111printer.TipoBtec.regular, Ng111printer.PesoBtec.bold
)
),
// ... (More elements of the ticket template)
];
// Create object to print
let impresion: Ng111printer.ImpresionBtec = {
accion: Ng111printer.AccionImpresion.imprimir,
confImpresora: configuracionImpresora,
plantillas: plantillaTicket,
copias: 1
};
// Call to the imprimir() function that receives our print object
this.conectorPrinterService.imprimir(
impresion).then((respuesta) => {
console.log("Impresion terminada", respuesta);
}).catch((error) => {
console.log("Error al imprimir.", error);
});
}
Starting from version 1.0.14 of ng111Printer, in conjunction with version 1.0.6 of the WIN_PRINTER_CONECTOR, you can now seamlessly integrate ESC/POS commands into your printing process. This enhancement allows you to send special commands, such as opening a cash drawer or performing other specific actions supported by your thermal printer.
To send ESC/POS commands, follow these steps:
-
Upgrade to Ng111Printer version 1.0.14:
Ensure that you have upgraded your Ng111Printer library to version 1.0.14:
npm install ng111printer@1.0.14
-
Download and Install WIN_PRINTER_CONECTOR version 1.0.6:
You can download and install WIN_PRINTER_CONECTOR version 1.0.6 from the following link: WIN_PRINTER_CONECTOR v1.0.6
After downloading, run the setup file to install the service. Ensure that the service is started either by restarting your PC or accessing the Services app and finding the service named WIN_PRINTER_CONECTOR, then right-click to start.
-
Sending ESC/POS Commands:
You can use the new
enviarComandoEscPos
function in theConectorPrinterService
to send ESC/POS commands. For example:// Example of sending an ESC/POS command to open a cash drawer this.conectorPrinterService.enviarComandoEscPos({ nombre: 'YourPrinterName', // Replace with your printer name comando: '27,112,0,25,250' // Replace with your ESC/POS command }).then((response) => { console.log("Command sent successfully:", response); }).catch((error) => { console.error("Error sending command:", error); });
Make sure to replace 'YourPrinterName' with the actual name of your printer and adjust the 'comando' parameter according to the specific ESC/POS command you want to send.
Now, you can leverage the power of ESC/POS commands to enhance your thermal printing experience with ng111Printer.
Please note that for ESC/POS commands to work, ensure that your printer is shared in the printer properties, and the shared name is used as the printer name when sending commands.