1000金币
本帖最后由 Richard.Huang 于 2023-9-28 14:41 编辑
产品:SpreadJS、GcExcel
版本:
问题编号:DOCXLS-8891、SJS-20210、DOCXLS-8927、DOCXLS-8959
- @PostMapping(value = "/pdf3")
- public ResponseEntity<byte[]> getPDF(@RequestBody Map<String, Object> mapReq) throws Exception {
- Workbook workbook = new Workbook();
- workbook.setEnableCalculation(true);
- JSONObject jsonObject = new JSONObject((Map)mapReq.get("data"));
- String json = jsonObject.toString();
- workbook.fromJson(json);
- java.io.ByteArrayOutputStream out = new ByteArrayOutputStream();
- workbook.save(out, SaveFileFormat.Pdf);
- byte[] contents = out.toByteArray();
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_PDF);
- // Here you have to set the actual filename of your pdf
- String filename = "output.pdf";
- headers.setContentDispositionFormData(filename, filename);
- headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
- ResponseEntity<byte[]> response = new ResponseEntity<>(contents, headers, HttpStatus.OK);
- return response;
- }
复制代码
|
|