0

我有这种方法可以从当前活动生成 PDF:

public boolean convertToPDF(String pdfFileName) {

    PdfDocument document = new PdfDocument();

    View content = GraphActivity.rl_main;
    int pageNumber = 1;
    PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(content.getWidth(),
    content.getHeight(), pageNumber).create();

    PdfDocument.Page page = document.startPage(pageInfo);

    content.draw(page.getCanvas());

    document.finishPage(page);

    pdfFile = new File(pdfFileName);

        try {
            pdfFile.createNewFile();
            OutputStream out = new FileOutputStream(pdfFile);
            document.writeTo(out);
            document.close();
            out.close();
        } catch (IOException e) {
            Log.e("Error", "Could not create PDF file!");
            return false;
        }
    return true;
}

出于某种原因,在 Marshmallow 中运行此方法时,我得到一个包含不可读字符的 PDF 文件。我已在运行时授予应用程序权限WRITE_EXTERNAL_STORAGE。我需要为 Marshmallow 做些什么不同的事情吗?我可以确认这适用于较旧的 Android 版本。

编辑:我在我的assets文件夹中使用自定义字体。我想知道这是否与它有关。

更新:我尝试禁用自定义字体,这解决了问题。但是,我更愿意保留我的自定义字体。

4

0 回答 0