ng111printer
TypeScript icon, indicating that this package has built-in type declarations

1.0.17 • Public • Published

Ng111printer

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.

Key Points

  • 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.

Versions

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

Installation and Uninstallation of WIN_PRINTER_CONECTOR

Installation

  1. Open the setup file.
  2. 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.

Uninstallation

  1. Access the Windows Control Panel.
  2. Find the program WIN_PRINTER_CONECTORvX.X.X.
  3. Click uninstall.

How to Use Ng111printer

  1. Install the package using npm in your Angular project:

    npm install ng111printer
  2. Import the library into the component where printing is needed:

    import * as Ng111printer from 'ng111printer';
  3. Initialize the ConectorPrinterService in the component's constructor:

    constructor(
        private conectorPrinterService: Ng111printer.ConectorPrinterService
    ) { }
  4. 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;
    });
  5. 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
    };
  6. Create the template structure:

    let ticketTemplate = [
        // Elements like images, text, QR codes, etc.
    ];
  7. Construct the print object:

    let print: Ng111printer.ImpresionBtec = {
        accion: Ng111printer.AccionImpresion.imprimir,
        confImpresora: printerConfiguration,
        plantillas: ticketTemplate,
        copias: 1
    };
  8. 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);
    });

Example 2

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);
    });
}

ESC/POS Commands (Added in version 1.0.14)

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.

How to Use ESC/POS Commands

To send ESC/POS commands, follow these steps:

  1. 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
  2. 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.

  3. Sending ESC/POS Commands:

    You can use the new enviarComandoEscPos function in the ConectorPrinterService 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.

Readme

Keywords

none

Package Sidebar

Install

npm i ng111printer

Weekly Downloads

0

Version

1.0.17

License

none

Unpacked Size

236 kB

Total Files

44

Last publish

Collaborators

  • hugo.hl