I need to convert pdf to byte array and vice versa.
Can any one help me?
This is how I am converting to byte array
public static byte[] conve
The problem is that you are calling toString()
on the InputStream
object itself. This will return a String
representation of the InputStream
object not the actual PDF document.
You want to read the PDF only as bytes as PDF is a binary format. You will then be able to write out that same byte
array and it will be a valid PDF as it has not been modified.
e.g. to read a file as bytes
File file = new File(sourcePath);
InputStream inputStream = new FileInputStream(file);
byte[] bytes = new byte[file.length()];
inputStream.read(bytes);