| @@ -28,12 +28,14 @@ import org.springframework.web.multipart.MultipartFile; | |||||
| @CrossOrigin(origins = "", allowedHeaders = "") | @CrossOrigin(origins = "", allowedHeaders = "") | ||||
| public class PdfController { | public class PdfController { | ||||
| private String pdf_path = "templates/pdf/"; | |||||
| // Endpoint to serve the initial template PDF | // Endpoint to serve the initial template PDF | ||||
| @GetMapping(value = "/template", produces = MediaType.APPLICATION_PDF_VALUE) | @GetMapping(value = "/template", produces = MediaType.APPLICATION_PDF_VALUE) | ||||
| public ResponseEntity<byte[]> getPdfTemplate() throws IOException { | public ResponseEntity<byte[]> getPdfTemplate() throws IOException { | ||||
| // Ensure your template PDF is in src/main/resources/static/ | // Ensure your template PDF is in src/main/resources/static/ | ||||
| ClassPathResource pdfFile = new ClassPathResource("static/template_form.pdf"); | |||||
| ClassPathResource pdfFile = new ClassPathResource(pdf_path + "HSBC B24102883_fillable_Financial Needs Analysis for Individual Nov2024.pdf"); | |||||
| if (!pdfFile.exists()) { | if (!pdfFile.exists()) { | ||||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body("PDF template not found.".getBytes()); | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("PDF template not found.".getBytes()); | ||||
| } | } | ||||
| @@ -45,12 +47,11 @@ public class PdfController { | |||||
| HttpHeaders headers = new HttpHeaders(); | HttpHeaders headers = new HttpHeaders(); | ||||
| headers.setContentDispositionFormData("inline", "template_form.pdf"); | headers.setContentDispositionFormData("inline", "template_form.pdf"); | ||||
| headers.setContentType(MediaType.APPLICATION_PDF); | headers.setContentType(MediaType.APPLICATION_PDF); | ||||
| System.out.println("chk+ " + pdfBytes); | |||||
| return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); | return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); | ||||
| } | } | ||||
| // Endpoint to receive the filled PDF from the frontend | // Endpoint to receive the filled PDF from the frontend | ||||
| @PostMapping(value = "/saveFilled", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | |||||
| @PostMapping(value = "/save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | |||||
| public ResponseEntity<Map<String, String>> saveFilledPdf(@RequestParam("file") MultipartFile file) { | public ResponseEntity<Map<String, String>> saveFilledPdf(@RequestParam("file") MultipartFile file) { | ||||
| if (file.isEmpty()) { | if (file.isEmpty()) { | ||||
| return ResponseEntity.badRequest().body(Map.of("message", "No file uploaded.")); | return ResponseEntity.badRequest().body(Map.of("message", "No file uploaded.")); | ||||