Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

convert base64 to pdf object for pdf reader in android studio

// HazaaZOOZ - java - how to convert base64 to pdf object for pdf reader in android studio - java

case PDF:
    try {
        byte[] pdfAsBytes = Base64.decode(file.getContent(), Base64.DEFAULT);
        File dir = getStorageDir();
        File pdffile = new File(dir, file.getName());
        if(!pdffile.exists())
        {
            pdffile.getParentFile().mkdirs();
            pdffile.createNewFile();
        }
        Files.write(pdfAsBytes, pdffile);
        Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
        pdfIntent.setDataAndType(Uri.fromFile(pdffile), "application/pdf");
        pdfIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(pdfIntent);
    } catch (IOException e) {
        e.printStackTrace();
    }

    break;
 
PREVIOUS NEXT
Tagged: #convert #pdf #object #pdf #reader #android #studio
ADD COMMENT
Topic
Name
3+2 =