I use the following method to add text to my generated QR code:
private static void insertText(BufferedImage source, String text, int x, int y) {
Graphics2D graph = source.createGraphics();
graph.setFont(new Font("Arial", Font.PLAIN, 12));
graph.setColor(Color.BLACK);
graph.drawString(text, x, y);
}
It adds the given text to the top of QR code. However, I want to draw JSON key-value pair as shown below as text, but I cannot see a proper method of Graphics2D
.
Instead of:
{ "id": 100, "name": "John", "surname": "Boython" }
I want to draw text as shown below:
id: 100
name: John
surname: Boython
So, how can I do this? Also, is there a wrap property for the drawing text of Graphics2D
?