PDF不显示中文

时间:2017-08-09 05:24:46

标签: android pdf itext pdf-generation

我正在使用iText生成PDF文档。我的文档中包含英文和中文数据。英文文本(始终)正确显示。中文不是。

这是我的代码:

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();

0 个答案:

没有答案