Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tried on capacitor 5 but does not work #54

Open
albgen opened this issue Nov 25, 2023 · 2 comments
Open

Tried on capacitor 5 but does not work #54

albgen opened this issue Nov 25, 2023 · 2 comments

Comments

@albgen
Copy link

albgen commented Nov 25, 2023

Just tried on capacitor 5 but it does not work. SDK30&31 both does not work.
The error i see is the following:
image

tPrinter is declared and used as per sample on the main page:


`
import { Printer, ThermalPrinterPlugin } from 'thermal-printer-cordova-plugin/src';

declare let tPrinter: ThermalPrinterPlugin;

tPrinter.listPrinters({type: 'bluetooth'}, function(printers) {
        alert(printers);
        if (printers.length > 0) {
            var pr = printers[0] as Printer;
            tPrinter.requestPermissions({
                type: 'bluetooth',
                id: 'SPP-R400'
            }, function() {
                // Permission granted - We can print!
                tPrinter.printFormattedText({
                    type: 'bluetooth',
                    id: 4,
                    text: '[C]<u> Hello World</u>' // new lines with "\n"
                }, function() {
                    console.log('Successfully printed!');
                }, function(error) {
                    console.error('Printing error', error);
                });
            }, function(error) {
                alert('Permission');
                console.error('Permission denied - We can\'t print!');
            });
        } else {
            console.error('No printers found!');
        }
    }, function(error) {
        console.error('Ups, we cant list the printers!', error);
    });
`

Another problem is that when you install it from npm:
npm install thermal-printer-cordova-plugin it will install a version old 2 years so the package also on npmjs should be updated.

@bobolat
Copy link

bobolat commented Jan 18, 2024

hi, this issues already solve?

@Drunkenpilot
Copy link

Just tried on capacitor 5 but it does not work. SDK30&31 both does not work. The error i see is the following: image

tPrinter is declared and used as per sample on the main page:


`
import { Printer, ThermalPrinterPlugin } from 'thermal-printer-cordova-plugin/src';

declare let tPrinter: ThermalPrinterPlugin;

tPrinter.listPrinters({type: 'bluetooth'}, function(printers) {
        alert(printers);
        if (printers.length > 0) {
            var pr = printers[0] as Printer;
            tPrinter.requestPermissions({
                type: 'bluetooth',
                id: 'SPP-R400'
            }, function() {
                // Permission granted - We can print!
                tPrinter.printFormattedText({
                    type: 'bluetooth',
                    id: 4,
                    text: '[C]<u> Hello World</u>' // new lines with "\n"
                }, function() {
                    console.log('Successfully printed!');
                }, function(error) {
                    console.error('Printing error', error);
                });
            }, function(error) {
                alert('Permission');
                console.error('Permission denied - We can\'t print!');
            });
        } else {
            console.error('No printers found!');
        }
    }, function(error) {
        console.error('Ups, we cant list the printers!', error);
    });
`

Another problem is that when you install it from npm: npm install thermal-printer-cordova-plugin it will install a version old 2 years so the package also on npmjs should be updated.

Hi you can try this package https://www.npmjs.com/package/thermal-printer-cordova-plugin-modified with version 1.0.8
And you should not call requestPermission method when the type of device is Bluetooth. also the id should be printer's address (bluetooth device), or deviceId (usb device), you could find those informations in the document.
Hope this could help.

Best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants