You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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."
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.
12
12
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.
14
14
15
15
The complete source code for the examples in this article is available on GitHub:
16
16
@@ -20,33 +20,40 @@ You can also browse all barcode generation examples in the [Generation examples
20
20
21
21
## Generate a basic GS1-128 barcode
22
22
23
-
The following example encodes GTIN, expiration date, and batch number.
23
+
The following example encodes a GTIN, expiration date, and batch number.
24
24
25
25
```java
26
26
BarcodeGenerator generator =newBarcodeGenerator(
27
27
EncodeTypes.GS_1_CODE_128,
28
-
"(01)09501101530008(17)251231(10)BATCH-42"
28
+
"(01)09501101530003(17)251231(10)BATCH-42"
29
29
);
30
30
31
+
// Example dimensions; verify them against the applicable GS1 specification
The code text contains the following Application Identifiers:
39
44
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.
43
50
44
51
## Encode common Application Identifiers
45
52
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.
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.
90
86
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.
92
88
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
94
90
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.
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.
115
114
116
115
## Fit GS1-128 into a target image box
117
116
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.
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.
138
136
139
137
## Create a compact GS1-128 layout
140
138
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.
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.
165
169
166
170
## Recommendations
167
171
168
172
- 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