2

I am using iText to generate a PDF document. My document has both English and Chinese data in it. The English text is (always) displayed properly. The chinese text is not.

This is my code:

File pdfFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "pdfdemo");

if (!pdfFolder.exists()) {
    pdfFolder.mkdir();
    Log.i("a", "Pdf Directory created");
}

//Create time stamp
myFile = new File(pdfFolder, "Demo.pdf");
OutputStream output = new FileOutputStream(myFile);

//Step 1
document = new Document();

//Step 2
PdfWriter.getInstance(document, output);                 

//Step 3
document.open();

//Step 4 Add content          
Float f = 4f;
Font headerFont = newFont(Font.FontFamily.TIMES_ROMAN, 22);                  
Paragraph p1 = new Paragraph();
p1.setAlignment(Paragraph.ALIGN_RIGHT);
p1.setFont(headerFont);
p1.setSpacingAfter(f);
p1.add("Snoxgen");

PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.addCell(getCell(getString(R.string.spo2)+" 100-90 : " + String.valueOf(Spo2100), PdfPCell.ALIGN_LEFT));
table.addCell(getCell(getString(R.string.snore1)+" 30-40 : " + Snore30, PdfPCell.ALIGN_RIGHT));            
document.add(p1);
document.add(table);                 

//Step 5: Close the document
document.close();
Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54

0 Answers0