Encode Non-English Characters in 2D Barcodes
Contents
[
Hide
]
You can generate 2D barcodes for non-English character sets, for example, Turkish, Chinese, Arabic, Latin, Greek and so on. The character limitation is 1000. The sample codes below generate barcodes for Turkish and Chinese characters.
Below are code snippets that create a Pdf417 barcode for Turkish and Chinese characters.
Create a Pdf417 Barcode with Turkish Characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(Pdf417BarcodeWithTurkishCharacters.class) + "TechnicalArticles/"; | |
// Generate the barcode | |
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.PDF_417); | |
// Set the code text | |
String codetext = "AYŞE" + "\n" + "Ümit" + "\n" + "Ümit@estee.com" + "\n" + "Türkiye"; | |
ByteBuffer bytebuffer = Charset.forName("windows-1254").encode(codetext); | |
byte[] bytes = bytebuffer.array(); | |
String codeText = new String(bytes); | |
gen.setCodeText(codeText); | |
// Set the display text | |
gen.getParameters().getBarcode().getCodeTextParameters().setTwoDDisplayText(codetext); | |
gen.save(dataDir + "barcode.png"); |
![]() |
---|
Figure: Sample Turkish Pdf417 barcode |
Create a Pdf417 Barcode with Chinese Characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(Pdf417BarcodeWithChineseCharacters.class) + "TechnicalArticles/"; | |
// Generate the barcode | |
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.PDF_417); | |
// Set the code text | |
String codetext = "被洪水困�的"; | |
ByteBuffer bytebuffer = Charset.forName("MS936").encode(codetext); | |
byte[] bytes = bytebuffer.array(); | |
String codeText = new String(bytes); | |
gen.setCodeText(codeText); | |
// Set the display text | |
gen.getParameters().getBarcode().getCodeTextParameters().setTwoDDisplayText(codetext); | |
gen.save(dataDir + "barcode.png"); |
![]() |
---|
Figure: A sample Chinese Pdf417 barcode |