Guest User

Untitled

a guest
Dec 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public byte[] readPDF() {
  2. File output = new File("C:\\Workspace\\Ksenija.pdf");
  3. Path pdfPath = null;
  4. byte[] pdf = null;
  5.  
  6. if(output.exists()){
  7. pdfPath = Paths.get("C:\\Workspace\\Ksenija.pdf");
  8. }
  9. else {System.out.print("nema podataka");}
  10. try {
  11. pdf = Files.readAllBytes(pdfPath);
  12. } catch (IOException e) {
  13. e.printStackTrace();
  14. }
  15. return pdf;
  16. }
  17.  
  18.  
  19. @Override
  20. public byte[] getPDF() {
  21. try {
  22. return this.jdbcTemplate.queryForObject("SELECT GENERIRANI_DOKUMENT FROM INS_RAZNO.CARGOPRIJAVA WHERE ID = 1", byte[].class);
  23. }
  24. catch(DataAccessException ex) {
  25. ex.printStackTrace();
  26. return null;
  27. }
  28. }
  29.  
  30. //////////////////////////////////////////////controler
  31.  
  32. @RequestMapping(value = "/download")
  33. public void writer() throws IOException {
  34. byte[] pdf = kDAO.getPDF();
  35. try(FileOutputStream fos = new FileOutputStream("C:\\Users\\y095722\\Desktop\\test.pdf")){
  36. fos.write(pdf);
  37. }
  38. catch(IOException ex) {
  39. ex.printStackTrace();
  40. }
  41. }
Add Comment
Please, Sign In to add comment