PDF to byte array and vice versa

前端 未结 13 1262
独厮守ぢ
独厮守ぢ 2020-11-27 04:19

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         


        
13条回答
  •  天命终不由人
    2020-11-27 04:55

    To convert pdf to byteArray :

    public byte[] pdfToByte(String filePath)throws JRException {
    
             File file = new File();
             FileInputStream fileInputStream;
             byte[] data = null;
             byte[] finalData = null;
             ByteArrayOutputStream byteArrayOutputStream = null;
    
             try {
                fileInputStream = new FileInputStream(file);
                data = new byte[(int)file.length()];
                finalData = new byte[(int)file.length()];
                byteArrayOutputStream = new ByteArrayOutputStream();
    
                fileInputStream.read(data);
                byteArrayOutputStream.write(data);
                finalData = byteArrayOutputStream.toByteArray();
    
                fileInputStream.close(); 
    
            } catch (FileNotFoundException e) {
                LOGGER.info("File not found" + e);
            } catch (IOException e) {
                LOGGER.info("IO exception" + e);
            }
    
            return finalData;
    
        }
    

提交回复
热议问题