Posts Tagged ‘site’

Conversion PDF to Byte and Vice verse

Posted: January 13, 2012 in Random Posts
Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Simple conversion easily enjoy the word of JAVA……………….

public static byte[] convertPDFToByteArray(String sourcePath) {
byte[] bytes=null;
InputStream inputStream;

File file = new File(sourcePath);

try {
inputStream = new FileInputStream(file);
bytes = new byte[(int)file.length()];
int read = inputStream.read(bytes);
} catch (IOException ex) {
Logger.getLogger(

DesktopApplication3View.class.getName()).log(Level.SEVERE, null, ex);
}return bytes;

}

public void convertByteArrayToPDF(String sourcePath,byte[] bytes) {
OutputStream out;
try {
out = new FileOutputStream(sourcePath);
try {
out.write(bytes);
out.close();
} catch (IOException ex) {
Logger.getLogger(DesktopApplication3View.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(DesktopApplication3View.class.getName()).log(Level.SEVERE, null, ex);
}

}