How to convert Byte Array to PDF file in Android?

I'm working on an application where i am getting the data in the form of byte array ,and i need to use this byte array for creating a new PDF file.How can i achieve this in android ?

29.6k 25 25 gold badges 91 91 silver badges 144 144 bronze badges asked Dec 27, 2011 at 12:08 1,671 4 4 gold badges 23 23 silver badges 43 43 bronze badges Check this out: Commented Dec 27, 2011 at 13:11

3 Answers 3

Here is one of the way of creating PDF from Byte Array.

File dir = Environment.getExternalStorageDirectory(); File assist = new File("/mnt/sdcard/Sample.pdf"); try < InputStream fis = new FileInputStream(assist); long length = assist.length(); if (length >Integer.MAX_VALUE) < Log.e("MainActivity", "cannnottt readddd"); >byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0) < offset += numRead; >File data = new File(dir, "mydemo.pdf"); OutputStream op = new FileOutputStream(data); op.write(bytes); > catch (Exception ex)