|
|
@@ -118,10 +118,61 @@ public class AppStandardFileController {
|
|
|
response.getOutputStream().write(bytes);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/getPdfLocal")
|
|
|
+ @Operation(summary = "预览模版pdf-本地测试")
|
|
|
+ public void getPdfLocal(@RequestParam(value = "file", required = true) MultipartFile file,
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
+ byte[] bytes = grapeCityApi.getPdfByte(file.getBytes()).getCheckedData();
|
|
|
+ response.getOutputStream().write(bytes);
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/getPDFByInspection")
|
|
|
@Operation(summary = "预览检验方案模版pdf")
|
|
|
public void getPDFByInspection(@RequestParam(value = "file", required = true) MultipartFile file,@RequestParam(value = "manualUrl") String manualUrl,
|
|
|
HttpServletResponse response) throws Exception {
|
|
|
+
|
|
|
+ // 调用另一个服务的 PDF 转换接口
|
|
|
+ String targetUrl = grapecityUrl+
|
|
|
+ "/pdf/getPdf";
|
|
|
+ byte[] fileBytes = file.getBytes();
|
|
|
+ List<byte[]> pdfBytesList = new ArrayList<>();
|
|
|
+ pdfBytesList.add(fileBytes);
|
|
|
+ // 发送 POST 请求获取 PDF 字节流
|
|
|
+ byte[] bytes = HttpUtil.createPost(targetUrl)
|
|
|
+ .body(JSONObject.toJSONString(pdfBytesList)).execute().bodyBytes();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(manualUrl)){
|
|
|
+
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ if (manualUrl.endsWith(".doc") || manualUrl.endsWith(".docx")) {
|
|
|
+ byte[] wordBytes = fileApi.getFileByPath(manualUrl).getData();
|
|
|
+ byteArrayOutputStream = WordToPdfUtils.doc2pdfOutStream(wordBytes);
|
|
|
+ } else {
|
|
|
+ byte[] bytes1 = fileApi.getFileByPath(manualUrl).getData();
|
|
|
+ byteArrayOutputStream.write(bytes1);
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayOutputStream mergeOutputStream = new ByteArrayOutputStream();
|
|
|
+ PDFMergerUtility mergerUtility = new PDFMergerUtility();
|
|
|
+ mergerUtility.addSource(new ByteArrayInputStream(bytes));
|
|
|
+ mergerUtility.addSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
+ // pdf 文件流合并
|
|
|
+ mergerUtility.setDestinationStream(mergeOutputStream);
|
|
|
+ mergerUtility.mergeDocuments(null);
|
|
|
+
|
|
|
+ response.getOutputStream().write(mergeOutputStream.toByteArray());
|
|
|
+ }else{
|
|
|
+ response.getOutputStream().write(bytes);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getPDFByInspectionLocal")
|
|
|
+ @Operation(summary = "预览检验方案模版pdf")
|
|
|
+ public void getPDFByInspectionLocal(@RequestParam(value = "file", required = true) MultipartFile file,@RequestParam(value = "manualUrl") String manualUrl,
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
+
|
|
|
byte[] bytes = grapeCityApi.getPdfByte(file.getBytes()).getCheckedData();
|
|
|
|
|
|
if (StringUtils.isNotEmpty(manualUrl)){
|