Skip to content

Commit 997b58f

Browse files
author
Aleksander Grinin
committed
Updated /java/developer-guide/barcode-generation/generate-gs1-128/
1 parent b0276b2 commit 997b58f

1 file changed

Lines changed: 56 additions & 50 deletions

File tree

  • java/developer-guide/barcode-generation/generate-gs1-128
Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
title: "Generate GS1-128 Barcodes"
3-
description: "Learn how to generate GS1-128 barcodes in Aspose.BarCode for Java, encode Application Identifiers, handle variable-length fields, configure print dimensions, and create compact layouts."
3+
description: "Learn how to generate GS1-128 barcodes in Aspose.BarCode for Java, encode Application Identifiers, handle variable-length fields, configure physical dimensions, and create compact or box-driven layouts."
44
type: docs
55
weight: 10
66
url: /java/developer-guide/barcode-generation/generate-gs1-128/
77
---
88

99
# Generate GS1-128 Barcodes
1010

11-
GS1-128 is based on Code 128 and uses GS1 Application Identifiers to encode structured supply-chain data such as GTIN, expiration date, batch number, and serial number.
11+
GS1-128 is based on Code 128 and uses GS1 Application Identifiers to encode structured supply-chain data such as GTIN, expiration date, batch or lot number, and serial number.
1212

13-
In Aspose.BarCode for Java, use `EncodeTypes.GS_1_CODE_128`. Application Identifiers can be written in parentheses, for example `(01)` for GTIN or `(17)` for expiration date. The generator processes the structured input and inserts FNC1 separators where required.
13+
In Aspose.BarCode for Java, use `EncodeTypes.GS_1_CODE_128`. Application Identifiers must be supplied in parenthesized form, for example `(01)` for GTIN and `(17)` for an expiration date. The parentheses make the structured input readable but are not encoded as ordinary data characters. The generator inserts the required GS1 field separator after a non-final variable-length field where needed.
1414

1515
The complete source code for the examples in this article is available on GitHub:
1616

@@ -20,33 +20,40 @@ You can also browse all barcode generation examples in the [Generation examples
2020

2121
## Generate a basic GS1-128 barcode
2222

23-
The following example encodes GTIN, expiration date, and batch number.
23+
The following example encodes a GTIN, expiration date, and batch number.
2424

2525
```java
2626
BarcodeGenerator generator = new BarcodeGenerator(
2727
EncodeTypes.GS_1_CODE_128,
28-
"(01)09501101530008(17)251231(10)BATCH-42"
28+
"(01)09501101530003(17)251231(10)BATCH-42"
2929
);
3030

31+
// Example dimensions; verify them against the applicable GS1 specification
3132
generator.getParameters().getBarcode().getXDimension().setMillimeters(0.33f);
3233
generator.getParameters().getBarcode().getBarHeight().setMillimeters(15.0f);
3334
generator.getParameters().setResolution(300.0f);
3435

36+
// Reserve horizontal quiet zones
37+
generator.getParameters().getBarcode().getPadding().getLeft().setMillimeters(3.5f);
38+
generator.getParameters().getBarcode().getPadding().getRight().setMillimeters(3.5f);
39+
3540
generator.save("gs1_128.png", BarCodeImageFormat.PNG);
3641
```
3742

3843
The code text contains the following Application Identifiers:
3944

40-
- `(01)` — GTIN;
41-
- `(17)` — expiration date in `YYMMDD` format;
42-
- `(10)` — batch or lot number.
45+
- `(01)` — a 14-digit GTIN including its check digit;
46+
- `(17)` — an expiration date in `YYMMDD` format;
47+
- `(10)` — a variable-length batch or lot number.
48+
49+
The dimensions in this example illustrate configuration in physical units. Required dimensions depend on the applicable GS1 application specification, label size, printing process, and scanning environment.
4350

4451
## Encode common Application Identifiers
4552

46-
Multiple fixed-length and variable-length data fields can be combined in one GS1-128 symbol.
53+
Multiple fixed-length and variable-length element strings can be combined in one GS1-128 symbol.
4754

4855
```java
49-
String gs1CodeText = "(01)09512345678900"
56+
String gs1CodeText = "(01)09512345678901"
5057
+ "(17)260630"
5158
+ "(10)LOT2025A"
5259
+ "(21)SERIAL123456";
@@ -60,42 +67,31 @@ generator.getParameters().getBarcode().getXDimension().setMillimeters(0.33f);
6067
generator.getParameters().getBarcode().getBarHeight().setMillimeters(16.0f);
6168
generator.getParameters().setResolution(300.0f);
6269

63-
// Configure left and right quiet zones
64-
generator.getParameters().getBarcode().getPadding().getLeft().setMillimeters(3.3f);
65-
generator.getParameters().getBarcode().getPadding().getRight().setMillimeters(3.3f);
70+
generator.getParameters().getBarcode().getPadding().getLeft().setMillimeters(3.5f);
71+
generator.getParameters().getBarcode().getPadding().getRight().setMillimeters(3.5f);
6672

67-
// Show human-readable text below the barcode
68-
generator.getParameters()
73+
CodetextParameters codeTextParameters = generator.getParameters()
6974
.getBarcode()
70-
.getCodeTextParameters()
71-
.setLocation(CodeLocation.BELOW);
75+
.getCodeTextParameters();
7276

73-
generator.getParameters()
74-
.getBarcode()
75-
.getCodeTextParameters()
76-
.getFont()
77-
.setFamilyName("Arial");
78-
79-
generator.getParameters()
80-
.getBarcode()
81-
.getCodeTextParameters()
82-
.getFont()
83-
.getSize()
84-
.setPoint(9);
77+
codeTextParameters.setLocation(CodeLocation.BELOW);
78+
codeTextParameters.setFontMode(FontMode.MANUAL);
79+
codeTextParameters.getFont().setFamilyName("Arial");
80+
codeTextParameters.getFont().getSize().setPoint(9);
8581

8682
generator.save("gs1_128_complete.png", BarCodeImageFormat.PNG);
8783
```
8884

89-
This layout is suitable for printed labels where dimensions and readable text must be controlled explicitly.
85+
`FontMode.MANUAL` is required when the explicitly configured font size must be used. In automatic font mode, the library calculates the font size from the barcode dimensions.
9086

91-
## Handle variable-length fields and FNC1
87+
The selected font family must be available in the runtime environment. Otherwise, Java may substitute another installed font.
9288

93-
Some GS1 Application Identifiers have variable-length values. If another field follows, a separator is required to mark the end of the variable-length data.
89+
## Handle variable-length fields and GS1 separators
9490

95-
When Application Identifiers are supplied in parenthesized form, Aspose.BarCode inserts FNC1 where required.
91+
Some GS1 Application Identifiers contain variable-length values. If another element string follows, the previous field must be terminated by a GS1 field separator.
9692

9793
```java
98-
String gs1CodeText = "(01)09501101530008"
94+
String gs1CodeText = "(01)09501101530003"
9995
+ "(10)LOT-ABC-999"
10096
+ "(21)SN00004567";
10197

@@ -108,66 +104,76 @@ generator.getParameters().getBarcode().getXDimension().setMillimeters(0.33f);
108104
generator.getParameters().getBarcode().getBarHeight().setMillimeters(15.0f);
109105
generator.getParameters().setResolution(300.0f);
110106

107+
generator.getParameters().getBarcode().getPadding().getLeft().setMillimeters(3.5f);
108+
generator.getParameters().getBarcode().getPadding().getRight().setMillimeters(3.5f);
109+
111110
generator.save("gs1_128_varlen.png", BarCodeImageFormat.PNG);
112111
```
113112

114-
Here `(10)` contains a variable-length lot number and is followed by `(21)`. The required field separator is handled by the generator.
113+
AI `(10)` contains a variable-length lot number and is followed by AI `(21)`. The generator inserts the required GS1 field separator between these element strings. A final variable-length field does not require a trailing separator.
115114

116115
## Fit GS1-128 into a target image box
117116

118-
Use `ImageWidth`, `ImageHeight`, and `AutoSizeMode.NEAREST` when the generated barcode must fit a predefined bitmap area.
117+
Use `ImageWidth`, `ImageHeight`, and `AutoSizeMode.NEAREST` when the barcode must fit a predefined bitmap area.
119118

120119
```java
121120
BarcodeGenerator generator = new BarcodeGenerator(
122121
EncodeTypes.GS_1_CODE_128,
123-
"(01)09501101530008(17)251231(10)BATCH-42"
122+
"(01)09501101530003(17)251231(10)BATCH-42"
124123
);
125124

126-
generator.getParameters().getBarcode().getXDimension().setMillimeters(0.33f);
127-
generator.getParameters().getBarcode().getBarHeight().setMillimeters(15.0f);
128-
125+
generator.getParameters().setResolution(300.0f);
129126
generator.getParameters().getImageWidth().setPixels(500);
130127
generator.getParameters().getImageHeight().setPixels(200);
131128
generator.getParameters().setAutoSizeMode(AutoSizeMode.NEAREST);
132-
generator.getParameters().setResolution(300.0f);
133129

134130
generator.save("gs1_128_box.png", BarCodeImageFormat.PNG);
135131
```
136132

137-
The target image box must still be large enough for the encoded content and the selected X-Dimension.
133+
`AutoSizeMode.NEAREST` calculates the effective X-dimension and bar height required to fit the symbol into the specified image box. Explicit `XDimension` and `BarHeight` values are ignored in this mode.
134+
135+
A fixed bitmap box does not guarantee compliance with physical print requirements. Validate the resulting module width, quiet zones, print size, and scanner readability for the intended application.
138136

139137
## Create a compact GS1-128 layout
140138

141-
The human-readable text can be hidden to reduce image height. Top and bottom padding can also be reduced.
139+
The human-readable text can be hidden and vertical padding can be reduced to lower the overall image height. Horizontal quiet-zone space must still be preserved.
142140

143141
```java
144142
BarcodeGenerator generator = new BarcodeGenerator(
145143
EncodeTypes.GS_1_CODE_128,
146-
"(01)09501101530008(17)251231(10)BATCH-42"
144+
"(01)09501101530003(17)251231(10)BATCH-42"
147145
);
148146

149147
generator.getParameters().getBarcode().getXDimension().setMillimeters(0.33f);
150148
generator.getParameters().getBarcode().getBarHeight().setMillimeters(12.0f);
151149
generator.getParameters().setResolution(300.0f);
152150

151+
// Disable human-readable text to reduce image height
153152
generator.getParameters()
154153
.getBarcode()
155154
.getCodeTextParameters()
156155
.setLocation(CodeLocation.NONE);
157156

157+
// Reduce vertical padding
158158
generator.getParameters().getBarcode().getPadding().getTop().setMillimeters(1.0f);
159159
generator.getParameters().getBarcode().getPadding().getBottom().setMillimeters(1.0f);
160160

161+
// Preserve horizontal quiet zones
162+
generator.getParameters().getBarcode().getPadding().getLeft().setMillimeters(3.5f);
163+
generator.getParameters().getBarcode().getPadding().getRight().setMillimeters(3.5f);
164+
161165
generator.save("gs1_128_minimal.png", BarCodeImageFormat.PNG);
162166
```
163167

164-
Keep sufficient left and right quiet zones even when reducing the vertical layout.
168+
Reducing human-readable text and vertical padding does not reduce the required horizontal quiet zones. A compact symbol must still be validated against the applicable GS1 application specification and tested with the intended printer and scanner.
165169

166170
## Recommendations
167171

168172
- Use `EncodeTypes.GS_1_CODE_128`, not regular `CODE_128`, for GS1-128 data.
169-
- Enter Application Identifiers in parenthesized form to make structured input readable.
170-
- Use valid data lengths and formats for each Application Identifier.
171-
- Allow the generator to insert FNC1 separators for variable-length fields.
172-
- Use physical units and an explicit resolution for print-oriented labels.
173-
- Test the final output with the actual label size, printer, and scanner.
173+
- Supply Application Identifiers in parenthesized form.
174+
- Use valid field lengths, formats, and check digits for every Application Identifier.
175+
- Let the generator insert separators after non-final variable-length fields.
176+
- Use `FontMode.MANUAL` when you need an explicitly configured human-readable text size.
177+
- Do not combine explicit `XDimension` and `BarHeight` values with `AutoSizeMode.NEAREST`.
178+
- Treat physical dimensions and quiet-zone sizes as application-specific values, not universal defaults.
179+
- Test the final symbol with the actual label size, printer, scanner, and operating environment.

0 commit comments

Comments
 (0)