Developer Guide >
PDF-417 Generation Guide
PDF-417 Barcode Sample Code & Barcode Property Settings
1. Generate PDF-417 in Java Class
The following Java code illustrates how to generate a PDF-417 barcode in a Java class
PDF417 barcode = new PDF417();
barcode.setProcessTilde(true);
barcode.setData("0123456789AaBbCcDeEeFfGgHhIiJjKkLl" +
"~009~126!@#$%^&*()_+`-={}[]:\"|;'\\<>?,./MmNnOoPpQqRrSs" +
"TtUuVvWwXxYyZz");
barcode.setEcl(PDF417.ECL_8);
barcode.setRowCount(30);
barcode.setColumnCount(5);
barcode.setDataMode(PDF417.MODE_AUTO);
barcode.setTruncated(true);
barcode.setMacro(true);
barcode.setMacroSegmentIndex(3);
barcode.setMacroSegmentCount(4);
barcode.setMacroFileIndex(64);
barcode.setUOM(uom);
barcode.setX(barWidth);
barcode.setBarRatio(barRatio);
barcode.setLeftMargin(leftMargin);
barcode.setRightMargin(rightMargin);
barcode.setTopMargin(topMargin);
barcode.setBottomMargin(bottomMargin);
barcode.setResolution(resolution);
barcode.setRotate(rotate);
barcode.renderBarcode("C://pdf417.gif");
// generate barcode to BufferedImage object
BufferedImage bufferedImage = linear.renderBarcode();
// generate barcode to byte[] object
byte[] barcodeBytes = linear.renderBarcodeToBytes();
// render barcode on Graphics2D
Graphics2D g = ...
Rectangle2D rectangle = ...
linear.renderBarcode(g, rectangle);
// generate barcode and output to OutputStream object
OutputStream outputStream = ...
linear.renderBarcode(outputStream);
2. Java PDF-417 Property Settings
-
Set the data property with the value to encode. Type is String.
Servlet URL Parameter: "Data".
-
Set the dataMode property. Default is PDF417.Text.
-
PDF417.AUTO (0): Barcode Library will use the different compaction modes and switching procedures automatically.
-
PDF417.MODE_TEXT (1) (default): It allows encoding all printable ASCII characters, i.e. values
from 32 to 126 inclusive in accordance with ISO/IEC 646, as well as selected
control characters such as TAB (horizontal tab ASCII 9), LF (NL line feed, new
line ASCII 10) and CR (carriage return ASCII 13)
-
PDF417.MODE_BYTE (2): It allows encoding all 256 possible 8-bit byte values. This
includes all ASCII characters value from 0 to 127 inclusive and provides for
international character set support
-
PDF417.MODE_NUMERIC (3): It allows encoding numeric data.
Servlet URL Parameter: "DataMode". Sample: &DataMode=1
-
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the encoding data. Default is false.
Format of the tilde:
- ~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
- ~6NNNNN: is used to represent the Unicode. NNNNN is from 00000 - 65535.
-
~7NNNNNN: is used to specify the Extended Channel Interpretations and NNNNNN is a value between
000000 and 999999.
-
~rp: is used only at the very beginning of the symbol for the reader programming purpose.
Servlet Parameter: "ProcessTilde". Value: "t" (true), "f" (false). Sample: &ProcessTilde=t
-
Set the ecl property. PDF417 Error Correction Level.
Default is PDF417.ECL_2 (2).
Servlet URL Parameter: "ECL". Sample: &ECL=2
-
Set the truncated property to true, if you want truncated PDF417.
Default is false.
truncated PDF417 may be used where space considerations are a primary concern and symbol damage is unlikely.
Servlet URL Parameter: "Truncated". Value: "t" (true), "f" (false). Sample: &Truncated=t
-
Set the column property value.
Number of columns. The value range is from 1 to 30. The default is 5. Increase this value, if your data size is large.
Servlet URL Parameter: "ColumnCount". Sample: &ColumnCount=5
-
Set the row property value.
The number of rows for PDF417. The value range is from 3 to 90. The default is 3.
Servlet URL Parameter: "RowCount". Sample: &RowCount=3
-
Macro PDF 417
PDF 417 can be divided into multiple data areas, also called Macro PDF 417. Conversely, information stored in multiple PDF417 symbols can be reconstructed as single data symbols.
- Set
isMacro property to true, then Macro PDF417 is enabled.
Servlet Parameter: "IsMacro".
- Set
macroSegmentCount property to the number of total symbols which make the sequence.
Servlet Parameter: "MacroSegmentCount".
- Set
macroSegmentIndex property to the position of current symbol in the secuence (Start with 0).
Servlet Parameter: "MacroSegmentIndex".
- Set
macroFileIndex property to be identified to the same file .
Servlet Parameter: "MacroFileIndex".
-
Barcode image size settings: How to control barcode size?
-
Set property uom (Unit of Measure) for properties X, Y, leftMargin, rightMargin, topMargin and bottomMargin.
Default is Linear.UOM_PIXEL (0). Valid values are Linear.UOM_PIXEL (0), Linear.UOM_CM (1), Linear.UOM_Inch (2).
Servlet URL Parameter: "UOM". Value: 0 (pixel), 1 (cm), 2 (inch). Sample: &UOM=0
-
Set the X (for barcode module width) and barRatio (barcode module height = X * barRatio) properties.
X type is float, default is 1.
barRatio type is int, default is 5.
Servlet URL Parameter: "X", "BarRatio".
-
Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float.
Default values are 0 for all 4 margin settings.
Servlet URL Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin". Sample: &LeftMargin=0
-
Set the resolution property (Value is expressed in DPI - Dots per inch).
Default is 72 dpi.
Servlet URL Parameter: "Resolution". Sample: &Resolution=72
-
With rotate property, you can display barcode horizontally or vertically.
Value can be
- 0 (Linear.ANGLE_0),
- 1 (Linear.ANGLE_90),
- 2 (Linear.ANGLE_180),
- 3 (Linear.ANGLE_270)
Default value is 0.
Servlet URL Parameter: "Rotate". Sample: &Rotate=0
3. All Barcode Types
|