Print QR Code

// Expert user has replied.
J Jose Margarido 1 year 4 months ago
1187 3 0

Hi,

Zebra ZQ220 plus printer, Android Studio, and Zebra Mobile TC21.
I can print text, etc., but I can't print the QR code through an ImageView image.
I have already checked the documentation and all the examples, but none of them work. They always print random characters. For example:

 

....
ImageView qrCodeImageView = findViewById(R.id.geraetiq_imageViewResult);
final Bitmap qrCodeBitmap = ((BitmapDrawable) qrCodeImageView.getDrawable()).getBitmap();

Connection connectprinter = new BluetoothConnection("XX:XX:XX:XX:XX:XX");
try {
    connectprinter.open();
    ZebraPrinter printer = ZebraPrinterFactory.getInstance(connectprinter);
    printer.reset();
    File tempFile = null;
    tempFile = File.createTempFile("temp_image", ".png", getCacheDir());
    FileOutputStream outputStream = new FileOutputStream(tempFile);
    qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
    outputStream.close();
    int x = 0;
    int y = 0;
    printer.printImage(tempFile.getAbsolutePath(), x, y,50,50,false);  // NOT WORK
    printer.printImage(new ZebraImageAndroid(qrCodeBitmap), 0, 0, qrCodeBitmap.getWidth(), qrCodeBitmap.getHeight(), false);  // NOT WORK
    String finalCommand = "! 0 50 20 100 1\r\nTEXT 4 0 20 20 " + "N: " + eTxt_NInterno.getText().toString() + "\r\nPRINT\r\n";
    printer.sendCommand(finalCommand); //WORK
    
    connectprinter.close();

} catch (ConnectionException e) {
    e.printStackTrace();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} catch (ZebraPrinterLanguageUnknownException e) {
    throw new RuntimeException(e);
} finally {
    try {
        connectprinter.close();
    } catch (ConnectionException e) {
        e.printStackTrace();
    }
}

 

 

What am I doing wrong?!!

Thank you!

Please Register or Login to post a reply

3 Replies

S Steven Si

ZQ220 printers are CPCL printers. By default, the ZebraPrinterFactory.getInstance(connectprinter) returns an instance for ZPL printer. In order to get an instance for CPCL printer, please pass in the PrinterLanguage.CPCL parameter. With the CPCL printer instance, you should be able to print the image of the barcode.

// Get a CPCL printer instance
ZebraPrinter printer = ZebraPrinterFactory.getInstance(PrinterLanguage.CPCL, connectprinter)
J Jose Margarido

Hi,

Thank you for the help. However, I have another problem: How can I print the image with only 3 cm of height? Regardless of the size I manipulate the image, the printer roll prints an additional 15 cm of empty space. How can this be resolved?

This my code:
 

try {
    connectprinter.open();
    ZebraPrinter printer = ZebraPrinterFactory.getInstance(PrinterLanguage.CPCL, connectprinter);
    
    printer.printImage(new ZebraImageAndroid(qrCodeBitmap), 0, 0, 250, 125, false);
    
    // Rest of the code...
} catch (ConnectionException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    throw new RuntimeException(e);
} finally {
    try {
        connectprinter.close();
    } catch (ConnectionException e) {
        e.printStackTrace();
    }
}

Regards

S Steven Si

Check the media.feed_length setting on the ZQ220 printer. Try to set the media.feed_length to the minimum, which is 25 dots for the ZQ220. You can either use the Printer Setup Utilities for Windows tool or use the API in the SGD class of the SDK to change the setting.

### Check the media.feed_length setting
! U1 getvar "media.feed_length"

### Set the media.feed_length to minimum 25
! U1 setvar "media.feed_length" "25"

 

CONTACT
Can’t find what you’re looking for?