JAVA-1088: Move java-generating-barcodes-qr-codes into spring-boot-libraries module
This commit is contained in:
@@ -8,9 +8,8 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -24,39 +23,6 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.barbecue</groupId>
|
||||
<artifactId>barbecue</artifactId>
|
||||
<version>${barbecue.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.barcode4j</groupId>
|
||||
<artifactId>barcode4j</artifactId>
|
||||
<version>${barcode4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>${zxing.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>javase</artifactId>
|
||||
<version>${zxing.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.kenglxn.qrgen</groupId>
|
||||
<artifactId>javase</artifactId>
|
||||
<version>${qrgen.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.rvesse</groupId>
|
||||
<artifactId>airline</artifactId>
|
||||
@@ -89,6 +55,16 @@
|
||||
<artifactId>takes</artifactId>
|
||||
<version>${takes.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>${httpcore.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
@@ -119,7 +95,7 @@
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>libraries-3</finalName>
|
||||
<plugins>
|
||||
@@ -239,10 +215,6 @@
|
||||
<properties>
|
||||
<jcommander.version>1.78</jcommander.version>
|
||||
<lombok.version>1.18.6</lombok.version>
|
||||
<barbecue.version>1.5-beta1</barbecue.version>
|
||||
<barcode4j.version>2.1</barcode4j.version>
|
||||
<zxing.version>3.3.0</zxing.version>
|
||||
<qrgen.version>2.6.0</qrgen.version>
|
||||
|
||||
<cactoos.version>0.43</cactoos.version>
|
||||
<airline.version>2.7.2</airline.version>
|
||||
@@ -254,6 +226,8 @@
|
||||
<aspectjweaver.version>1.9.2</aspectjweaver.version>
|
||||
|
||||
<takes.version>1.19</takes.version>
|
||||
<httpcore.version>4.4.13</httpcore.version>
|
||||
<httpclient.version>4.5.12</httpclient.version>
|
||||
<velocity-engine-core.version>2.2</velocity-engine-core.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
package com.baeldung.barcodes;
|
||||
|
||||
import com.baeldung.barcodes.generators.BarbecueBarcodeGenerator;
|
||||
import com.baeldung.barcodes.generators.Barcode4jBarcodeGenerator;
|
||||
import com.baeldung.barcodes.generators.QRGenBarcodeGenerator;
|
||||
import com.baeldung.barcodes.generators.ZxingBarcodeGenerator;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/barcodes")
|
||||
public class BarcodesController {
|
||||
|
||||
//Barbecue library
|
||||
|
||||
@GetMapping(value = "/barbecue/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barbecueUPCABarcode(@PathVariable("barcode") String barcode) throws Exception {
|
||||
return okResponse(BarbecueBarcodeGenerator.generateUPCABarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/barbecue/ean13/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barbecueEAN13Barcode(@PathVariable("barcode") String barcode) throws Exception {
|
||||
return okResponse(BarbecueBarcodeGenerator.generateEAN13BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/barbecue/code128", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barbecueCode128Barcode(@RequestBody String barcode) throws Exception {
|
||||
return okResponse(BarbecueBarcodeGenerator.generateCode128BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/barbecue/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barbecuePDF417Barcode(@RequestBody String barcode) throws Exception {
|
||||
return okResponse(BarbecueBarcodeGenerator.generatePDF417BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
//Barcode4j library
|
||||
|
||||
@GetMapping(value = "/barcode4j/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barcode4jUPCABarcode(@PathVariable("barcode") String barcode) {
|
||||
return okResponse(Barcode4jBarcodeGenerator.generateUPCABarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/barcode4j/ean13/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barcode4jEAN13Barcode(@PathVariable("barcode") String barcode) {
|
||||
return okResponse(Barcode4jBarcodeGenerator.generateEAN13BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/barcode4j/code128", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barcode4jCode128Barcode(@RequestBody String barcode) {
|
||||
return okResponse(Barcode4jBarcodeGenerator.generateCode128BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/barcode4j/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> barcode4jPDF417Barcode(@RequestBody String barcode) {
|
||||
return okResponse(Barcode4jBarcodeGenerator.generatePDF417BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
//Zxing library
|
||||
|
||||
@GetMapping(value = "/zxing/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> zxingUPCABarcode(@PathVariable("barcode") String barcode) throws Exception {
|
||||
return okResponse(ZxingBarcodeGenerator.generateUPCABarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/zxing/ean13/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> zxingEAN13Barcode(@PathVariable("barcode") String barcode) throws Exception {
|
||||
return okResponse(ZxingBarcodeGenerator.generateEAN13BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/zxing/code128", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> zxingCode128Barcode(@RequestBody String barcode) throws Exception {
|
||||
return okResponse(ZxingBarcodeGenerator.generateCode128BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/zxing/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> zxingPDF417Barcode(@RequestBody String barcode) throws Exception {
|
||||
return okResponse(ZxingBarcodeGenerator.generatePDF417BarcodeImage(barcode));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/zxing/qrcode", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> zxingQRCode(@RequestBody String barcode) throws Exception {
|
||||
return okResponse(ZxingBarcodeGenerator.generateQRCodeImage(barcode));
|
||||
}
|
||||
|
||||
//QRGen
|
||||
|
||||
@PostMapping(value = "/qrgen/qrcode", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<BufferedImage> qrgenQRCode(@RequestBody String barcode) throws Exception {
|
||||
return okResponse(QRGenBarcodeGenerator.generateQRCodeImage(barcode));
|
||||
}
|
||||
|
||||
private ResponseEntity<BufferedImage> okResponse(BufferedImage image) {
|
||||
return new ResponseEntity<>(image, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.barcodes;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.BufferedImageHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootApp.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpMessageConverter<BufferedImage> createImageHttpMessageConverter() {
|
||||
return new BufferedImageHttpMessageConverter();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.baeldung.barcodes.generators;
|
||||
|
||||
import net.sourceforge.barbecue.Barcode;
|
||||
import net.sourceforge.barbecue.BarcodeFactory;
|
||||
import net.sourceforge.barbecue.BarcodeImageHandler;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BarbecueBarcodeGenerator {
|
||||
|
||||
private static final Font BARCODE_TEXT_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 14);
|
||||
|
||||
public static BufferedImage generateUPCABarcodeImage(String barcodeText) throws Exception {
|
||||
Barcode barcode = BarcodeFactory.createUPCA(barcodeText); //checksum is automatically added
|
||||
barcode.setFont(BARCODE_TEXT_FONT);
|
||||
barcode.setResolution(400);
|
||||
|
||||
return BarcodeImageHandler.getImage(barcode);
|
||||
}
|
||||
|
||||
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) throws Exception {
|
||||
Barcode barcode = BarcodeFactory.createEAN13(barcodeText); //checksum is automatically added
|
||||
barcode.setFont(BARCODE_TEXT_FONT);
|
||||
|
||||
return BarcodeImageHandler.getImage(barcode);
|
||||
}
|
||||
|
||||
public static BufferedImage generateCode128BarcodeImage(String barcodeText) throws Exception {
|
||||
Barcode barcode = BarcodeFactory.createCode128(barcodeText);
|
||||
barcode.setFont(BARCODE_TEXT_FONT);
|
||||
|
||||
return BarcodeImageHandler.getImage(barcode);
|
||||
}
|
||||
|
||||
public static BufferedImage generatePDF417BarcodeImage(String barcodeText) throws Exception {
|
||||
Barcode barcode = BarcodeFactory.createPDF417(barcodeText);
|
||||
barcode.setFont(BARCODE_TEXT_FONT);
|
||||
|
||||
return BarcodeImageHandler.getImage(barcode);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.baeldung.barcodes.generators;
|
||||
|
||||
import org.krysalis.barcode4j.impl.code128.Code128Bean;
|
||||
import org.krysalis.barcode4j.impl.pdf417.PDF417Bean;
|
||||
import org.krysalis.barcode4j.impl.upcean.EAN13Bean;
|
||||
import org.krysalis.barcode4j.impl.upcean.UPCABean;
|
||||
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Barcode4jBarcodeGenerator {
|
||||
|
||||
public static BufferedImage generateUPCABarcodeImage(String barcodeText) {
|
||||
UPCABean barcodeGenerator = new UPCABean();
|
||||
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
|
||||
|
||||
barcodeGenerator.generateBarcode(canvas, barcodeText);
|
||||
return canvas.getBufferedImage();
|
||||
}
|
||||
|
||||
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) {
|
||||
EAN13Bean barcodeGenerator = new EAN13Bean();
|
||||
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
|
||||
|
||||
barcodeGenerator.generateBarcode(canvas, barcodeText);
|
||||
return canvas.getBufferedImage();
|
||||
}
|
||||
|
||||
public static BufferedImage generateCode128BarcodeImage(String barcodeText) {
|
||||
Code128Bean barcodeGenerator = new Code128Bean();
|
||||
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
|
||||
|
||||
barcodeGenerator.generateBarcode(canvas, barcodeText);
|
||||
return canvas.getBufferedImage();
|
||||
}
|
||||
|
||||
public static BufferedImage generatePDF417BarcodeImage(String barcodeText) {
|
||||
PDF417Bean barcodeGenerator = new PDF417Bean();
|
||||
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
|
||||
barcodeGenerator.setColumns(10);
|
||||
|
||||
barcodeGenerator.generateBarcode(canvas, barcodeText);
|
||||
return canvas.getBufferedImage();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.baeldung.barcodes.generators;
|
||||
|
||||
import net.glxn.qrgen.javase.QRCode;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class QRGenBarcodeGenerator {
|
||||
|
||||
public static BufferedImage generateQRCodeImage(String barcodeText) throws Exception {
|
||||
ByteArrayOutputStream stream = QRCode
|
||||
.from(barcodeText)
|
||||
.withSize(250, 250)
|
||||
.stream();
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(stream.toByteArray());
|
||||
|
||||
return ImageIO.read(bis);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.baeldung.barcodes.generators;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.oned.Code128Writer;
|
||||
import com.google.zxing.oned.EAN13Writer;
|
||||
import com.google.zxing.oned.UPCAWriter;
|
||||
import com.google.zxing.pdf417.PDF417Writer;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ZxingBarcodeGenerator {
|
||||
|
||||
public static BufferedImage generateUPCABarcodeImage(String barcodeText) throws Exception {
|
||||
UPCAWriter barcodeWriter = new UPCAWriter();
|
||||
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.UPC_A, 300, 150);
|
||||
|
||||
return MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
}
|
||||
|
||||
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) throws Exception {
|
||||
EAN13Writer barcodeWriter = new EAN13Writer();
|
||||
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.EAN_13, 300, 150);
|
||||
|
||||
return MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
}
|
||||
|
||||
public static BufferedImage generateCode128BarcodeImage(String barcodeText) throws Exception {
|
||||
Code128Writer barcodeWriter = new Code128Writer();
|
||||
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.CODE_128, 300, 150);
|
||||
|
||||
return MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
}
|
||||
|
||||
public static BufferedImage generatePDF417BarcodeImage(String barcodeText) throws Exception {
|
||||
PDF417Writer barcodeWriter = new PDF417Writer();
|
||||
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.PDF_417, 700, 700);
|
||||
|
||||
return MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
}
|
||||
|
||||
public static BufferedImage generateQRCodeImage(String barcodeText) throws Exception {
|
||||
QRCodeWriter barcodeWriter = new QRCodeWriter();
|
||||
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.QR_CODE, 200, 200);
|
||||
|
||||
return MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user