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.