Skip to content

Commit 96cce10

Browse files
committed
Adds Barcode sample
1 parent 71a4391 commit 96cce10

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

application/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<artifactId>custom-stack-branding</artifactId>
2727
<version>1.0.0-SNAPSHOT</version>
2828
</dependency>
29+
<dependency>
30+
<groupId>uk.org.okapibarcode</groupId>
31+
<artifactId>okapibarcode</artifactId>
32+
<version>0.3.3</version>
33+
</dependency>
2934

3035
<!-- Core -->
3136
<dependency>

demo-application/barcode.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { response } from "sdk/http";
2+
3+
const Code128 = Java.type("uk.org.okapibarcode.backend.Code128");
4+
const BufferedImage = Java.type("java.awt.image.BufferedImage");
5+
const Java2DRenderer = Java.type("uk.org.okapibarcode.output.Java2DRenderer");
6+
const Color = Java.type("java.awt.Color");
7+
const File = Java.type("java.io.File");
8+
const ImageIO = Java.type("javax.imageio.ImageIO");
9+
const FileUtils = Java.type("org.apache.commons.io.FileUtils");
10+
11+
const barcode = new Code128();
12+
barcode.setFontName("Monospaced");
13+
barcode.setFontSize(16);
14+
barcode.setContent("custom-stack-1234");
15+
16+
const image = new BufferedImage(barcode.getWidth(), barcode.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
17+
const g2d = image.createGraphics();
18+
const renderer = new Java2DRenderer(g2d, 1, Color.WHITE, Color.BLACK);
19+
renderer.render(barcode);
20+
21+
const file = new File("code128.png");
22+
ImageIO.write(image, "png", file);
23+
24+
const bytes = FileUtils.readFileToByteArray(file);
25+
26+
response.setContentType("image/png");
27+
response.write(bytes);
28+
response.flush();
29+
response.close();

0 commit comments

Comments
 (0)