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

is it possible to print text and barcode OR image with one command #1

Open
j-agathos opened this issue Nov 13, 2017 · 1 comment
Open

Comments

@j-agathos
Copy link

j-agathos commented Nov 13, 2017

thank you for the great plugin, it works perfectly, with Text or Barcode or QR
is it possible to print text and barcode OR image with one command like:

cordova.plugins.bixolonPrint.addLine({
text: "hello cordova!\r\n",
textAlign: cordova.plugins.bixolonPrint.TextAlign.CENTER,
fontStyle: cordova.plugins.bixolonPrint.FontStyle.BOLD
});
cordova.plugins.bixolonPrint.printBarCodeOrSomeThing({
text: value,
alignment: 'left', // left, center, right
width: 2, // 1 - 6,
height: 150,
barcodeSystem: cordova.plugins.bixolonPrint.BarCodeSystem.CODE128,
characterPosition: cordova.plugins.bixolonPrint.BarCodeCharacterPosition.BELOW_BAR_CODE
});
cordova.plugins.bixolonPrint.printImageOrSomeThing({
base64Image: b64Image,
alignment: 'left', // left, center, right
width: 2, // 1 - 6,
height: 150,
});

cordova.plugins.bixolonPrint.printComboTextBarcodeImage();

@j-agathos j-agathos changed the title print barcode and text into the same function is it possible to print text and barcode OR image with one command Nov 13, 2017
@sebastiangrebe
Copy link

I am having the same issue.
As I have researched this it is currently not possible to run multiple commands at once because cordova/exec is used to send over the command. Each time you run a new command it replaces the last command that should be run. Maybe I have looked wrong but I think this must be the problem here.

My use case is that I want to print first text then a QR code and last another text.
What I did now is that I have set the fontType of the QR code to "qr" and added it just as text.
Then I have edited the BixolonPrint.java like this:

for (int i = 0; i < arlength; i++) {
            try {
                textLine = textLines.getJSONObject(i);
                fontType = textLine.optString("fontType");
                align = textLine.optString("textAlign");
                textAlignment = this.getAlignment(align);
                text = textLine.optString("text");

                if (hrBCode.equals(text.substring(0, Math.min(4, text.length())))) {
                    String hrStr = text.substring(text.length() - 1);
                    text = "";
                    for (int j = 0; j < paperWidth; j++) {
                        text += hrStr;
                    }
                    text += "\r\n";
                }
                if(fontType.equals("qr")) {
                    mBixolonPrinter.printQrCode(text, textAlignment, 50, 8, true);
                } else {
                    Log.d(TAG, "BixolonPrint.printText: line:" + (i + 1) + " of " + arlength);

                    width = textLine.optInt("textWidth");
                    height = textLine.optInt("textHeight");
                    fontStyle = textLine.optString("fontStyle");
                    textAttribute = this.getAttribute(fontType, fontStyle);
                    textSize = this.getTextSize(width, height);

                    // mBixolonPrinter.printText(text + "\r\n", textAlignment, textAttribute, textSize, false);
                    mBixolonPrinter.printText(text, textAlignment, textAttribute, textSize, false);
                }
            } catch (JSONException e2) {
                this.isValidAction = false;
                this.actionError = "print error: " + e2.getMessage();
                this.disconnect();
                return;
            }
        }

Here the text is printed as QR code if the fontType is "qr".

I know that this is not a clean approach but it works for me.

The best would be to have a have command which takes an array of commands executing them one by one.

If you have another solution I am open for suggestions.

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