Generating QR Code for Different Data - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!
  • Home
  • /
  • Blog
  • /
  • Generating QR Code for Different Data

Generating QR Code for Different Data

QR codes are a form of 2-Dimensional barcode – QR is an acronym of Quick Response code, but they may also be referred to as Denso Barcodes. Created by Denso Wave in 1994, QR codes represented a fascinating step forward for the visual representation of binary data. Moving beyond the simple lines-and-spaces approach of previous barcodes, QR codes store information as a matrix, allowing a greater complexity of data and greater efficiency of space. Initially, the automotive sector was the main use for which QR codes were planned, and later they became broadly accepted as part of promotional campaigns and packaging: anywhere there needs to be an interface between physical/print media and digital media, QR codes are valuable. They are particularly popular specifically in mobile apps, where by means of a QR Code scanner app, one can easily scan a QR code to display text or access the campaign’s landing page.

QR Code SDK Features

QR Codes: how they hold data, and what platforms you can use

The information encoded in a QR code can be comprised of five standardized kinds of data numeric data (digits 0-9), alphanumeric data (digits, uppercase letters A-Z, characters (for example, space, %, $, +, -, *, /, etc.), Kanji characters and byte data.

There are a variety of options for accessing QR Code generator elements through software:

Benefits of using QR Code

There are many benefits of using QR Codes. The key benefits include the ability to bridge the offline media to the online world. So, if you have a QR Code, you can use it to log in, do a transaction, or other things for which the app is programmed too. There are different types of QR Codes including Vcard, URL, E-mail, Facebook, and so on!

One example is for login. If you are trying to use WhatsApp on your computer, you will be prompted to scan the QR code from your mobile. This eases out the long login process which would require the use of sensitive data. Other key benefits include reduced printing costs as it can easily be transferred from one device to another via the use of the screenshots or share option.

In short, QR codes are cheap, reliable, and remove the unnecessary steps required to complete an action. 

QR Code vs. Barcodes

Before we go and discuss the QR code creation process, it is important to learn about how it differs from Barcodes.

If you are new to QR Code, you might think QR Code builds on Barcodes and are the new thing in fashion. In reality, it is not. Barcodes enable businesses or traders to identify the items so that they can manage their inventory. They use it on consumer packaged goods(CPGs).

QR Code can also hold information, but it is important to know the differences it holds compared to barcodes. The key difference includes

  • QR Codes are differently shaped compared to barcodes. Barcodes are mostly rectangular so that the scanner can scan them and register on the system. QR-Codes, on the other hand, are square-shaped and have the ability to show data both horizontally and vertically.
  • The QR Codes can also be used to hold more data compared to barcodes. This is possible because of its square space.
  • QR Codes also hold different types of data which is beneficial when it comes to real-world implementation and use-cases.

Creating QR Codes

While there are various complex development tools that enable you to create QR codes unless you’re playing with QR codes as a technical exercise, you actually need your QR code to be made so you can integrate it into a larger project; and that’s what you need to be able to spend your time on. The pdf.co QR code generator from ByteScout allows you huge flexibility, including the ability to create QR codes with a form factor in compliance with more than 50 different standards, and allows insertion of data to barcodes from a range of sources and types, including geolocation, email, social media links, specific content you wish to highlight from your website, and more.

No installation is needed; the code is entirely web-based. Security is covered by the fact that all QR codes are removed from the server as soon as they are created, and QR codes are transmitted using SSL secure servers, making the tool safe for use.

The program also allows you to scan in existing QR codes, to analyze their function.

If you are doing a code project, however, you could compare your QR code created with pdf.co to the product of your own dev process, as in the following example, which will create a QR code image, and allow information to be read from the QR code image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.imageio.ImageIO;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
public class QR_Code {
public static void main(String[] args) throws WriterException, IOException,
            NotFoundException {
        String QR_Code_Data = "Hey Universe!";
        String file_Path = "QR_Code.png";
        String char_set = "UTF-8"; // or "ISO-8859-1"
        Map hint_Map = new HashMap();
        Hint_Map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        createQRCode(QR_Code_Data, file_Path, char_set, hint_Map, 150, 150);
        System.out.println("Successful Creation of QR Code image!");
        System.out.println("Let’s read data from QR Code: "
                + read_QR_Code(file_Path, char_set, hint_Map));
    }
public static void createQRCode(String QR_Code_Data, String file_Path,
            String char_set, Map hint_Map, int QR_Code_height, int QR_Code_width)
            throws WriterException, IOException {
        BitMatrix matrix = new MultiFormatWriter().encode(
                new String(QR_Code_Data.getBytes(char_set), char_set),
                BarcodeFormat.QR_CODE, QR_Code_width, QR_Code_height, hint_Map);
        MatrixToImageWriter.writeToFile(matrix, filePath.substring(file_Path
                .lastIndexOf('.') + 1), new File(file_Path));
    }
public static String read_QR_Code(String file_Path, String char_set, Map hint_Map)
            throws FileNotFoundException, IOException, NotFoundException {
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
                new BufferedImageLuminanceSource(
                        ImageIO.read(new FileInputStream(file_Path)))));

And from all of that, here’s what we get:

QR Code

And, as another example, try this. If you can’t follow the code, use the image to see the output!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.File;
import java.awt.Color;
import java.io.IOException;
import java.awt.Graphics2D;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import com.google.zxing.WriterException;
import com.google.zxing.EncodeHintType;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class QR_Code_Generation{
    public static void main(String[] args) throws WriterException, IOException {
        String QR_Code_Text = "http://www.Jesse.com";
        String Path_of_the_file = "E:\\Huda\\QRC.png";
        int size = 200;
        String Type_of_the_file = "png";
        File QR_File = new File (Path_of_the_file);
        createQRImage(QR_File, QR_Code_Text, size, Type_of_the_file);
        System.out.println("It’s generating smoothly!");
    }
    private static void createQRImage(File QR_File, String QR_Code_Text, int size,
            String Type_of_the_file) throws WriterException, IOException {
        // Form the Byte-Matrix for the Quick Response Code that encodes the provided String
        Hashtable hint_Map = new Hashtable();
        hint_Map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        QRCodeWriter QR_Code_Writer = new QRCodeWriter();
        BitMatrix Matrix_byte = QR_Code_Writer.encode(QR_Code_Text,
                BarcodeFormat.QR_CODE, size, size, hint_Map);
        // Creation of Buffered-Image; it will hold the QR Code
        int Width_of_Matrix = Matrix_byte.getWidth();
        BufferedImage image = new BufferedImage(Width_of_Matrix, Width_of_Matrix,
                BufferedImage.TYPE_INT_RGB);
        image.createGraphics();
        Graphics2D graphics = (Graphics2D) image.getGraphics();
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, Width_of_Matrix, Width_of_Matrix);
        // By means of the Matrix_byte, paint as well as save the image
        graphics.setColor(Color.BLACK);
        for (int a = 0; a < Width_of_Matrix; a++) {
            for (int b = 0; b < Width_of_Matrix; b++) {
                if (Matrix_byte.get(a, b)) {
                    graphics.fillRect(a, b, 1, 1);

The output of this code is shown below:

New QR Code

Using QR Codes on your site

One popular jQuery plugin for QR code generation is jquery.qrcode.js, which enables the user to add QR code to the web pages in an easy way, without depending on external services. It is based on a library that generates QR codes in a number of languages.

To use it, start by including it on your web page with the following tag:

1
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20type%3D%22text%2Fjavascript%22%20src%3D%22jquery.qrcode.min.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>">

After that, form a DOM element that will hold the generated QR code image. And after that, add the QR code to the container like so:

jquery(‘#qrcode’).qrcode(“Wow, it’s lovely to use this plugin”);

Generating a QR Code in Java can be a simple and smooth process if you use the right libraries, and this can be just the starting point. If you need a good way of introducing a digital interface-point to physical functionality, QR codes are a great bridge. Get started and see what they can do for you!

   

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.  
prev
next