0

I am working on project to create a live inline file (e.g DOCX, PDF, txt, JSON etc.. ) preview in browser , while editing any file using java springboot web application.

I have tried below code which opens e.g: pdf file in a new tab in browser. But what I am trying to do is to preview the file live along side while editing it.

@GetMapping
    public ResponseEntity<InputStreamResource> previewLive() {

        String filePath = "/path/";
        String fileName = "fileName.pdf";
        File file = new File(filePath+fileName);
        HttpHeaders headers = new HttpHeaders();      
        headers.add("content-disposition", "inline;filename=" +fileName);
        
        InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

        return ResponseEntity.ok()
                .headers(headers)
                .contentLength(file.length())
                .contentType(MediaType.parseMediaType("application/pdf"))
                .body(resource);
    }

One way I could think of is converting the file to image and display page wise on browser in the same place side by side where i am editing my file using an existing online editor.

Any way or a point to direction I can look for would be really helpful.

backToStack
  • 101
  • 6

1 Answers1

0

Deducted from this post it's not possible to edit and render pdf at the same time in browser using js/spring.

However if you edit the pdf in the corresponding software(Acrobat etc.) f.ex. LiveReload could be the tool you're looking for.

Akira Taguchi
  • 111
  • 1
  • 7
  • pdf was just an example , i am not looking for any tool or software rather a library that can render live while the file is being edited, one way i thought of convert FILE -> IMAGE and display page wise preview. – backToStack Jul 16 '21 at 05:58
  • @backToStack if a library is something you're looking for [spring-dev-tools](https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/howto-hotswapping.html) is the way to go. Do keep in mind the transactional state of each "saveable" file. – Akira Taguchi Jul 16 '21 at 06:16