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

Printing recipes in some cases being random? #24

Closed
Riley1101 opened this issue Feb 21, 2022 · 2 comments
Closed

Printing recipes in some cases being random? #24

Riley1101 opened this issue Feb 21, 2022 · 2 comments

Comments

@Riley1101
Copy link

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
Copy link
Owner

@Riley1101 please try to using async await #19 (comment)

@Riley1101
Copy link
Author

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

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

2 participants