Answers for "base64 to pdf"

0

convert base64 to pdf in java

// HazaaZOOZ - java- How to convert base64 to pdf in java or android studio

import java.io.File;
import java.io.FileOutputStream;
import java.util.Base64;

class Base64DecodePdf {
  public static void main(String[] args) {
    File file = new File("./test.pdf");

    try ( FileOutputStream fos = new FileOutputStream(file); ) {
      // 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
      String b64 = "JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==";
      byte[] decoder = Base64.getDecoder().decode(b64);

      fos.write(decoder);
      System.out.println("PDF File Saved");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Posted by: Guest on January-11-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language