convert base64 to pdf in android studio

Solutions on MaxInterview for convert base64 to pdf in android studio by the best coders in the world

showing results for - "convert base64 to pdf in android studio"
Jannik
07 Jan 2019
1import java.io.File;
2import java.io.FileOutputStream;
3import java.util.Base64;
4
5class Base64DecodePdf {
6  public static void main(String[] args) {
7    File file = new File("./test.pdf");
8
9    try ( FileOutputStream fos = new FileOutputStream(file); ) {
10      // To be short I use a corrupted PDF string, so make sure to use a valid one if you want to preview the PDF file
11      String b64 = "JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==";
12      byte[] decoder = Base64.getDecoder().decode(b64);
13
14      fos.write(decoder);
15      System.out.println("PDF File Saved");
16    } catch (Exception e) {
17      e.printStackTrace();
18    }
19  }
20}