Encode Non-English Characters in 2D Barcodes

Below are code snippets that create a Pdf417 barcode for Turkish and Chinese characters.

Create a Pdf417 Barcode with Turkish 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");
todo:image_alt_text
Figure: Sample Turkish Pdf417 barcode

Create a Pdf417 Barcode with Chinese 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");
todo:image_alt_text
Figure: A sample Chinese Pdf417 barcode