Я создаю PDF-документы в Android с использованием itextpdf5, моя проблема в том, что я не могу использовать символы Юникода, например (\ U24ea (⓪) \ U2460 (①) ......... ② ③), Я перепробовал много примеров, найденных в документации к itextpdf 5, но не работает, но в logcat они обычно отображаются. спасибо за любые предложения, вот код:
public class MainActivity extends AppCompatActivity {
public static final String DEST = "/file.pdf";
public static final String cnfreebd = "resources/font/cnfreebd.ttf";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
createPdf();
PDFView pdfView = findViewById(R.id.pdfView);
File file = getPublicAlbumStorageDir(DEST);
pdfView.fromFile(file).load();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
public File getPublicAlbumStorageDir(String albumName) {
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), albumName);
return file;
}
public void createPdf() throws IOException, DocumentException {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_CONTACTS)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
0);
}
} else {
}
if (isExternalStorageWritable()) {
File file = getPublicAlbumStorageDir(DEST);
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
PdfPCell UnicodeCercleNumber1 = new PdfPCell(new Paragraph("\u2460"));
PdfPCell UnicodeCercleNumber2 = new PdfPCell(new Paragraph("\u2461"));
PdfPCell UnicodeCercleNumber3 = new PdfPCell(new Paragraph("\u2462"));
Log.i("tag","(1) => \u2460");
Log.i("tag","(1) => \u2461");
Log.i("tag","(1) => \u2462");
table.addCell(UnicodeCercleNumber1);
table.addCell(UnicodeCercleNumber2);
table.addCell(UnicodeCercleNumber3);
document.add(table);
document.close();
}
}
}