Skip to content

yuanyouxi/qr-code-to-console

Repository files navigation

Qr Code to Console

A library to print zxing qr code to console. Inspired by QrToTerminal which support Java 11 or above.

Write this project to support Java 8.

Getting started

Maven

<dependency>
    <groupId>xyz.dunjiao.cloud</groupId>
    <artifactId>qr-to-console</artifactId>
    <version>1.0</version>
</dependency>

Print to console directly

BitMatrix bitMatrix = qrCodeWriter.encode(input, BarcodeFormat.QR_CODE, size, size, hintMap);
QRCodeUtils.print(bitMatrix, true);

Get the string use later like in Spring Shell

BitMatrix bitMatrix = qrCodeWriter.encode(input, BarcodeFormat.QR_CODE, size, size, hintMap);
return QRCodeUtils.toString(bitMatrix, true);

Console support

Windows powershell change encoding

chcp 437

Linux suggest to set lang to en_US.UTF-8

For Xshell display the QR code correctly, need to uncheck properties→terminal→Treat Ambiguously sized characters as wide