thiendangit / react-native-thermal-receipt-printer-image-qr

React native thermal receipt printer
https://www.npmjs.com/package/react-native-thermal-receipt-printer-image-qr
112 stars 73 forks source link

Printing recipes in some cases being random? #24

Closed Riley1101 closed 2 years ago

Riley1101 commented 2 years ago

Can someone help me with printing text in some cases being random? It's like 20 out of 1 in even the data is static it still prints randomly.

Here is my printer config

` // printer configs

    const CENTER = COMMANDS.TEXT_FORMAT.TXT_ALIGN_CT;
    let FONT_SIZE = COMMANDS.TEXT_FORMAT.TXT_CUSTOM_SIZE(1, 1);
    let LINE = COMMANDS.TEXT_FORMAT.TXT_FONT_B;
    let formatLine = (context) => {
        return `${LINE}${FONT_SIZE}${context}${FONT_SIZE}${LINE}`;
    };
    const BOLD_ON = COMMANDS.TEXT_FORMAT.TXT_BOLD_ON;
    let printDate = dateformat(new Date(), 'dddd, mmmm dS, yyyy, h:MM TT');
    let columnAliment = [ColumnAliment.LEFT, ColumnAliment.LEFT];
    let columnWidth = [10, 30];
    let itemWidth = [10, 30];
    const encoder = new EscPosEncoder();
    let _encoder = encoder
        .initialize()
        .align('center')
        .line('Scan to track your parcel')
        .line('ID : ReQYEJK')
        .qrcode('https://pohmal.com?ref= ReQYEJK')
        .encode();
    let base64String = Buffer.from(_encoder).toString('base64');

    let senderList = [
        ['Name ', 'Kyaw Ye Zaw'],
        ['Phone ', '+959 555 276'],
        ['Address ', 'No 45,Bet 24th Street and 2nd Avenue,Yangon,Myanmar'],
    ];
    let receiverList = [
        ['Name ', 'Kyaw Ye Zaw'],
        ['Phone ', '+959 555 276'],
        ['Address ', 'No 45,Bet 24th Street and 2nd Avenue,Yangon,Myanmar'],
    ];
    let itemList = [
        ['Item', 'Plates'],
        ['Charges', '1000 Ks'],
        ['COD    ', '1000 Ks'],
        ['Remark ', 'Careful about what you buy and what you pay for because you can lose your money'],
    ];

    // printing process

    try {
        if (Platform.OS === 'android' || Platform.OS === 'ios') {
            BLEPrinter.printImage('image_logo.jpg');
            BLEPrinter.printText(formatLine(`${printDate}`));
            BLEPrinter.printText(`${CENTER}${LINE}${FONT_SIZE}-----------------------------------------${FONT_SIZE}${LINE}${CENTER}`);
            BLEPrinter.printColumnsText(['SENDER', ''], columnWidth, columnAliment, [`${BOLD_ON}${LINE}${FONT_SIZE}${FONT_SIZE}${LINE}${BOLD_ON}`, '']);
            for (let i in senderList) {
                BLEPrinter.printColumnsText(senderList[i], columnWidth, columnAliment, [`${LINE}${FONT_SIZE}${FONT_SIZE}${LINE}`, '']);
            }
            BLEPrinter.printText(`${LINE}${formatLine('.............')}`);
            BLEPrinter.printColumnsText(['RECEIVER', ''], columnWidth, columnAliment, [`${BOLD_ON}${LINE}${FONT_SIZE}${FONT_SIZE}${LINE}${BOLD_ON}`, '']);
            for (let i in receiverList) {
                BLEPrinter.printColumnsText(receiverList[i], columnWidth, columnAliment, [`${LINE}${FONT_SIZE}${FONT_SIZE}${LINE}`, '']);
            }
            BLEPrinter.printText(`${CENTER}${LINE}${FONT_SIZE}..........................................${FONT_SIZE}${LINE}${CENTER}`);
            for (let i in itemList) {
                BLEPrinter.printColumnsText(itemList[i], itemWidth, columnAliment, [`${LINE}${FONT_SIZE}${FONT_SIZE}${LINE}`, '']);
            }
            BLEPrinter.printText(`${CENTER}${LINE}${FONT_SIZE}..........................................${FONT_SIZE}${LINE}${CENTER}`);
            BLEPrinter.printRaw(base64String);
            BLEPrinter.printText(`${CENTER}${LINE}${FONT_SIZE}-----------------------------------------${FONT_SIZE}${LINE}${CENTER}`);
        }

    } catch (err) {
        console.warn(err);
    }

`

Here is example printing randomly as the name printing out of its order

error

Here is example printing as it should be when I reprint again with the same settings and data.In short I just pressed the print button again

success

thiendangit commented 2 years ago

@Riley1101 please try to using async await https://github.com/thiendangit/react-native-thermal-receipt-printer-image-qr/issues/19#issuecomment-1002730997

Riley1101 commented 2 years ago

My God thank you . i didnt see the issue #19 my bad