Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何添加Unicode圆圈数字①②③;使用itextpdf 5创建pdf文档的步骤_Java_Android_Pdf - Fatal编程技术网

Java 如何添加Unicode圆圈数字①②③;使用itextpdf 5创建pdf文档的步骤

Java 如何添加Unicode圆圈数字①②③;使用itextpdf 5创建pdf文档的步骤,java,android,pdf,Java,Android,Pdf,我使用itextpdf5在android中创建PDF文档,我的问题是我不能使用unicode字符,例如(\U24ea)(⓪) \U2460(①)......... ② ③), 我尝试了itextpdf 5文档中的许多示例,但都不起作用,但在logcat中它们通常会出现。感谢您的建议,以下是代码: public class MainActivity extends AppCompatActivity { public static final String DEST = "/file.pd

我使用itextpdf5在android中创建PDF文档,我的问题是我不能使用unicode字符,例如(\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();
        }
    }
}

您正在使用的文件名为
cnfreebd.ttf
的字体组合数不包含
U+2460..U+2473
的Unicode范围内的任何字符

它使用非标准符号映射来定义“带圆圈的数字”,并将“左手”和“右手”分开:


因此,要获得
⓪ ① ②,而不是
“\u2460\u2461\u2462”
,您需要输入
“\uf070\uf071\uf077”

我很确定该字体不支持这些字符。请找到一种支持这些字符的字体,并在段落对象中使用。@ZAkZAk:您可能需要扩展它。这就是您正在使用的字体,不可否认。那么,一定是出了什么问题。在Android studio的Logcat中,它工作正常,但在应用程序中不起作用Pdf,我试过很多种字体,但都有同样的问题work@ZAkZAk:您可能需要知道我看不到您的屏幕。“它不工作”没有帮助–您看到了什么?可能显式的“符号”编码
U+F0xx
需要是普通的
U+00xx
(没有
U+F000
)。