Android 不显示中文的PDF
我正在使用iText生成PDF文档。我的文档中有中英文数据。英文文本(始终)正确显示。中文文本不是 这是我的代码:Android 不显示中文的PDF,android,pdf,itext,pdf-generation,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 Director
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();
您是否在类路径中添加了
itext asian.jar
尝试此链接请查看此官方文档链接,它可能会对您有所帮助