Pink Jazz
Pink Jazz

Reputation: 802

Android - PdfDocument not working properly in Marshmallow with custom typefaces

I have this method to generate a PDF from the current activity:

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;
}

For some reason, when running this method in Marshmallow, I get a PDF file with unreadable characters. I have granted the app permission WRITE_EXTERNAL_STORAGE at runtime. Is there anything I need to do different for Marshmallow? I can confirm this works on older Android versions.

EDIT: I am using custom typefaces in my assets folder. I wonder if this has anything to do with it.

UPDATE: I tried disabling the custom typefaces, and that fixes the issue. However, I would prefer to preserve my custom typefaces.

Upvotes: 0

Views: 405

Answers (0)

Related Questions