How to Print QR Codes with a POS Printer: Difference between revisions

From wizarPOS
(Replaced content with "{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/printer/print-qr-codes}}")
Tag: Replaced
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Generate QR code bitmap ==
{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/printer/print-qr-codes}}
Generates a QR code bitmap. The code snippet is as follows:
<syntaxhighlight lang="java">
    public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
        Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(); 
hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight); 
int width = matrix.getWidth(); 
int height = matrix.getHeight(); 
int[] pixels = new int[width * height]; 
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) { 
        if (matrix.get(x, y)) { 
            pixels[y * width + x] = 0xff000000; 
        } else {
            pixels[y * width + x] = 0xffffffff;
        }
    } 
        } 
Bitmap bitmap = Bitmap.createBitmap(width, height, 
              Bitmap.Config.ARGB_8888); 
bitmap.setPixels(pixels, 0, width, 0, 0, width, height); 
return bitmap; 
    } 
</syntaxhighlight >
 
== Print the QR code bitmap ==
Call print API to print bitmap. The code snippet is as follows:
<syntaxhighlight lang="java">
printerDevice =
        (PrinterDevice) POSTerminal.getInstance().getDevice("cloudpos.device.printer");
printerDevice.open();
printerDevice.printBitmap(bitmap);
printerDevice.close();
</syntaxhighlight >

Latest revision as of 07:41, 7 April 2024

Please visit new link of same subject:

https://smartpossdk.gitbook.io/cloudpossdk/faq/printer/print-qr-codes

We're making a move! Our site's content is migrating to a new URL, to provide you with an enhanced browsing experience. Please update your bookmarks accordingly. Thank you for your continuous support!