LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

Create Web QR Code with One Tag

Posted at

There may be occasions when you happen to need to create barcodes and QR codes. For Java, I often use barcode4j and zxing. Pass a string to the class and receive an image. In the case of the web, it is all about displaying the image on the web screen. Since it is basically a "routine task", I thought it would be a good idea to automate it, so I combined it into one tag.

Get Jar

<dependency>
    <groupId>io.github.efwgrp</groupId>
    <artifactId>efw</artifactId>
    <version>4.07.000</version>
</dependency>
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>core</artifactId>
    <version>3.4.0</version>
</dependency>

How to Write Jsp

Set the URL of the img tag to drawServlet, specify the type and msg, and receive the image. Strictly speaking, it's not a customization tag, but a servlet.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="efw" uri="efw" %>
<!DOCTYPE HTML>
<HTML>
<HEAD>
	<title>barcode テスト</title>
	<efw:Client lang="jp"/>
	<style>img{vertical-align:middle}</style>
	
</HEAD>
<BODY>
qrcode <img src="drawServlet?type=qrcode&msg=hellword" height="150px"> 
codabar <img src="drawServlet?type=codabar&msg=0123456789" height="60px"> 
code39 <img src="drawServlet?type=code39&msg=0123456789" height="60px"> 
code128 <img src="drawServlet?type=code128&msg=0123456789" height="60px"> 
2of5 <img src="drawServlet?type=2of5&msg=0123456789" height="60px"> 
itf14 <img src="drawServlet?type=itf14&msg=01234567891231" height="60px"> 
ean13 <img src="drawServlet?type=ean13&msg=1234567890128" height="60px"> 
ean8 <img src="drawServlet?type=ean8&msg=12345670" height="60px"> 
upca <img src="drawServlet?type=upca&msg=012345678905" height="60px"> 
upce <img src="drawServlet?type=upce&msg=01234565" height="60px"> 
rmcbc <img src="drawServlet?type=rmcbc&msg=0123456789" height="60px"> 
postnet <img src="drawServlet?type=postnet&msg=0123456789" height="60px"> 
usps4cb <img src="drawServlet?type=usps4cb&msg=0123456709498765432101234567891" height="60px"> 
pdf417 <img src="drawServlet?type=pdf417&msg=0123456789" height="60px"> 
datamatrix <img src="drawServlet?type=datamatrix&msg=0123456789" height="150px"> 
</BODY>
</HTML>

Result of execution

The following is what I created.
image.png

Among various codes, only QR code accepts parameters of numbers, alphabets, kanji, and symbols. This allows you to express URLs and has a wide range of uses.

Attachment, Code Type Explanation

Type Explanation
qrcode QR (Quick Response) code is a matrix-type two-dimensional code developed by Denso Wave (Japan) in 1994. It has the characteristics of extremely fast reading speed and the ability to store large amounts of data. Also, since the code was developed in Japan, it can efficiently express kanji and other characters. Therefore, it is widely used not only in Japan but also in countries and regions other than Japan that use kanji (China, South Korea, Taiwan, Hong Kong, etc.).
codabar NW-7 is a relatively early barcode developed by Monarch Marking Company (USA) in 1972. In Japan, it is mainly called NW-7, but it is also sometimes called CODABAR or Code 2 of 7. NW-7 uses seven bars and spaces of Narrow and Wide widths to represent one character, and this feature is the origin of the name. Due to the relatively simple construction of binary-level barcodes, high precision printing is not required.
code39 Code39 is a barcode developed by Intermec (USA) in 1975. Code39 uses nine bars and spaces (three of which are thick elements) to represent one character, and this feature is the origin of the name. Due to the relatively simple construction of binary-level barcodes, high precision printing is not required.
code128 Code128 is a barcode developed by Computer Identics (USA) in 1981. In order to correspond to computer input, it can express 128 characters of ASCII code, and 128 is the origin of the name. Due to its high information density and reliability, it is widely adopted in the industrial field as an alternative to Code 39.
2of5 Code 2 of 5 (Industrial 2 of 5) is the oldest barcode still in use, developed in 1970 by Identicon (USA) and Computer Identics (USA). is. This name comes from the fact that five bars (two of which are thick bars) are used to represent one character. It was originally used for industrial purposes, but it is now rarely used in the industrial field due to its low information density and inability to represent the alphabet. Various barcodes were developed from Code 2 of 5 because of its very simple configuration.
itf14 ITF is a barcode developed by Intermec (USA) in 1972. While conventional barcodes only represent characters using bars, ITF can also represent characters using spaces, so it has a high information density and was adopted as the standard symbol for packaging and delivery in the United States in 1981. ITF stores data in the spaces between (1) bars (Interleaved: between), and (2) five bars or spaces (two of which are thick) to represent one character. It has the characteristic that it uses elements), and this characteristic is the origin of the name.
ean13 EAN-13 is a widely recognized barcode in Europe, used in supermarkets and other retail stores with basic product recognition methods. It is the European equivalent of the US's UPC-A barcode. EAN stands for European Article Number, which is technically an International Article Number and is also used outside Europe.
ean8 EAN-8 barcodes are a shortened version of EAN-13 barcodes and are used as standard retail product identifiers in Europe and other countries. EAN stands for European Article Number, which has been renamed to International Article Number. However, "EAN" is still used today. EAN-8 (8 digits) is used for small packages, while EAN-13 codes (13 digits) are not.
upca UPC-A barcodes are the most commonly used and most widely recognized type of barcode in the United States. Mainly used in retail and grocery stores. UPC-A was developed by the Uniform Grocery Product Code Council in collaboration with IBM and has been in use since 1974. The first UPC barcode scanned was Wrigley's Juicy Fruit gum. The package is on display at the Smithsonian.
upce The UPC-E barcode is the Uniform Product Code and is the most widely used barcode in the United States. UPC-E is a shortened version of the standard-sized UPC-A numeric barcode used in retail stores across the country, including grocery stores. The shortened version is used for small products whose packaging is small and there is no space to place the full-sized UPC-A code.
rmcbc RM4SCC might be the correct abbreviation.Royal Mail 4 State Customer Code (commonly known as RM4SCC) is a two-dimensional barcode developed by Royal Mail in the UK. A two-dimensional barcode developed by the Royal Mail Company in the United Kingdom and used to indicate the postal code of letters and parcels within the United Kingdom. This system is also used in other countries, but it is one of its variations. The printed code is optimized for fast reading.
postnet POSTNET stands for Postal Numeric Encoding Technique, and is used to sort mail to be delivered using the ZIP code (postal code) of the destination. You've probably seen it as printing on certain envelopes. This is a very different type of barcode than barcodes used in retail and other data storage applications. Although relatively short in height, they are generally longer in length than traditional models.
usps4cb Intelligent Mail barcodes are also known as USPS OneCode solutions or USPS Four-State Customer Barcodes (4CBs, or USPS4CBs). Intelligent Mail barcode consists of 65 bars. Intelligent Mail barcodes, or OneCode, combine both postal code and tracking information, benefiting both the mailer and the post office. Intelligent Mail Barcode or OneCode replaces POSTNET and PLANET barcodes.
pdf417 PDF417 is a two-dimensional code developed by Symbol Technology (USA/currently Motorola) in 1989. The name PDF417 comes from the initials of ① Portable Data File and ② the basic unit (codeword) consists of 17 modules of 4 bars and 4 spaces. doing. PDF417 is a stacked two-dimensional code that can be read even with low-cost laser scanners, the vertical and horizontal designs can be easily changed, and it has excellent error correction functions, so it has been highly evaluated and adopted from various fields. I did. In particular, it has been adopted as a standard symbol for EDI data in the international standard logistics label (ISO 15394/JIS X 0515).
datamatrix DataMatrix is a matrix-type two-dimensional code developed by IDMatrix (USA) in 1987. In Japan, it is also called DataCode. DataMatrix has older versions ECC000-140 and a relatively new version ECC200. ECC000 to 140 have the disadvantage that there are few readers that handle distortion easily, so they are hardly used at present. On the other hand, ECC200 can store large amounts of data, has high reading performance, and is still widely used today. Therefore, unless otherwise specified regarding DataMatrix, this website describes ECC200.

This sample can be downloaded from the link below.

※Reference

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up