cowinapi / developer.cowin

This group is created to facilitate technical and integration discussions related to cowin platform. API related contents can be obtained at API setu portal https://apisetu.gov.in/public/marketplace/api/cowin
115 stars 30 forks source link

Binary data of the pdf in android #428

Open shivamPatwal opened 3 years ago

shivamPatwal commented 3 years ago

i had successfully done Authorization using volley library in android and in response i am getting binary content.can someone help me how to convert this binary content to pdf using java...please provide code

badinenisaivardhan commented 3 years ago

hey @shivamPatwal hope this will work on java

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); ) { String b64 = "your binary stringdata"; byte[] decoder = Base64.getDecoder().decode(b64); fos.write(decoder); System.out.println("PDF File Saved"); } catch (Exception e) { e.printStackTrace(); } } }

shekharkumar86 commented 3 years ago

i had successfully done Authorization using volley library in android and in response i am getting binary content.can someone help me how to convert this binary content to pdf using java...please provide code @shivamPatwal did you check this solution? its working or not please confirm.

shekharkumar86 commented 3 years ago

hey @shivamPatwal hope this will work on java

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); ) { String b64 = "your binary stringdata"; byte[] decoder = Base64.getDecoder().decode(b64); fos.write(decoder); System.out.println("PDF File Saved"); } catch (Exception e) { e.printStackTrace(); } } }

getting java.lang.IllegalArgumentException: Illegal base64 character 25 error