Java: Need to create PDF from byte-Array

后端 未结 4 1943
逝去的感伤
逝去的感伤 2021-02-02 13:20

From a DB2 table I\'ve got blob which I\'m converting to a byte array so I can work with it. I need to take the byte array and create a PDF out of it.

This

4条回答
  •  天命终不由人
    2021-02-02 14:06

     public static String getPDF() throws IOException {
    
            File file = new File("give complete path of file which must be read");
            FileInputStream stream = new FileInputStream(file);
            byte[] buffer = new byte[8192];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int bytesRead;enter code here
            while ((bytesRead = stream.read(buffer)) != -1) {
                baos.write(buffer, 0, bytesRead);
            }
            System.out.println("it came back"+baos);
            byte[] buffer1= baos.toByteArray();
            String fileName = "give your filename with location";
    
            //stream.close();
            
            
             FileOutputStream outputStream =
                        new FileOutputStream(fileName);
             
             outputStream.write(buffer1);
            
             return fileName;
            
        }
    

提交回复
热议问题