There is an application with fields:

Surname Name Patronymic Telephone Identifier

What are the options for implementing the generation of QR-code in java? Maybe there are libraries, or ready-made solutions? Maybe somewhere described how to implement it?

public void onQR(ActionEvent actionEvent) { String fam = "Тестовый"; String im = "Тест"; String ot = "Тестович"; String phone = "tel:89999999999"; String mail = "mailto:test@test.ru"; String url = "urlto:https://test.ru"; String contact = "mecard:" + fam + " " + im + " " + ot + ", г. Тестовск"; String rez = contact + "," + phone + "," + mail + "," + url; try { generateQRCodeImage(rez, 350, 350, QRIMG); } catch (WriterException ex) { System.out.println("Could not generate QR Code, WriterException :: " + ex.getMessage()); } catch (IOException ex) { System.out.println("Could not generate QR Code, IOException :: " + ex.getMessage()); } } 

enter image description here

1 answer 1

ZXing and QRGen .

 public class CreateQrCode { public static void main(String... args){ ByteArrayOutputStream bout = QRCode.from("your text") .withSize(250, 250) .to(ImageType.PNG) .stream(); try { OutputStream out = new FileOutputStream("qr-code.png"); bout.writeTo(out); out.flush(); out.close(); } catch (FileNotFoundException e){ e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } 

Code examples

  • Are there any libraries where you can transfer not just a string, but fields Name Phone Mile Website, etc.? So that they are like separate fields when scanning? I hope clearly described what I mean - Natalia Sergeevna
  • @ NataliaSergeevna, look: github.com/zxing/zxing/wiki/Barcode-Contents - gil9red
  • Read the article. tried to do. In my question I added a method in which I do all this and read the QR code. The first there is the Russian language is not displayed, instead of it the signs "?", And the second everything goes in one line. Is it possible to make everything in a column in the form of the type Phone: 89999999999, E-mail: test@test.ru, etc.? - Natalia Sergeevna
  • @ NataliaSergeevna, it seems you don’t quite understand the essence of QR codes) This is not a beautiful label for presenting data, but a way to encode it) Mark the code to be encoded as you want (the newline character is also a character, therefore it can be easily encoded) and pack in QR - Kir_Antipov
  • I correctly understand that you can only submit 1 line to the input, breaking it up as I need characters to go to a new line, etc.? I just thought that in the QR code you can separately transfer the fields Phone, Mile, URL, NAME but apparently not, only one line - Natalia Sergeevna