Commit fc52fd80 authored by chase's avatar chase

merge 档案管理

parent b2ffa029
...@@ -115,8 +115,8 @@ public class TaxDocumentController { ...@@ -115,8 +115,8 @@ public class TaxDocumentController {
*/ */
@PostMapping("/previewPDF") @PostMapping("/previewPDF")
@ResponseBody @ResponseBody
public void previewPDF(@RequestBody TaxDocumentDto taxDocumentDto) { public String previewPDF(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) {
taxDocumentService.previewPDF(taxDocumentDto.getPath()); return taxDocumentService.previewPDF2(response,taxDocumentDto.getPath());
/*InputStream is = null; /*InputStream is = null;
ByteArrayOutputStream os = null; ByteArrayOutputStream os = null;
try { try {
......
...@@ -175,9 +175,11 @@ public class FileTypesServiceImpl { ...@@ -175,9 +175,11 @@ public class FileTypesServiceImpl {
* @param fileTypes * @param fileTypes
*/ */
private void requiredFieldFormatToJson(FileTypes fileTypes) { private void requiredFieldFormatToJson(FileTypes fileTypes) {
if (fileTypes.getRequiredField().size() > 0) { if (null != fileTypes.getRequiredField() && fileTypes.getRequiredField().size() > 0) {
String requiredFieldJson = JSONObject.toJSONString(fileTypes.getRequiredField()); String requiredFieldJson = JSONObject.toJSONString(fileTypes.getRequiredField());
fileTypes.setRequiredFieldJson(requiredFieldJson); fileTypes.setRequiredFieldJson(requiredFieldJson);
}else{
throw new RuntimeException("必填字段没有填写");
} }
} }
......
...@@ -432,10 +432,11 @@ public class TaxDocumentServiceImpl { ...@@ -432,10 +432,11 @@ public class TaxDocumentServiceImpl {
} }
} }
public void previewPDF(String path) { public void previewPDF(HttpServletResponse response ,String path) {
String imageType = "PNG"; String imageType = "PNG";
OutputStream sos = null; OutputStream sos = null;
try { try {
sos = response.getOutputStream();
PDFToImg(sos, path, getPDFNum(path), imageType); PDFToImg(sos, path, getPDFNum(path), imageType);
} catch (IOException e) { } catch (IOException e) {
log.error("PDF转换图片异常: " + e.getMessage()); log.error("PDF转换图片异常: " + e.getMessage());
...@@ -1217,4 +1218,45 @@ public class TaxDocumentServiceImpl { ...@@ -1217,4 +1218,45 @@ public class TaxDocumentServiceImpl {
} }
return is; return is;
} }
public String previewPDF2(HttpServletResponse response , String path) {
InputStream is = null;
ByteArrayOutputStream os = null;
String dUrlData;
//pdf源路径
byte[] buff = new byte[1024];
int len;
try {
is = getInputStreamByUrl(path);
os = new ByteArrayOutputStream();
while ((len = is.read(buff)) != -1) {
os.write(buff, 0, len);
}
os.flush();
os.toByteArray();
dUrlData = Base64.getEncoder().encodeToString(os.toByteArray());
} catch (IOException e) {
log.error(e.getMessage());
throw new RuntimeException("pdf转换错误");
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
log.error(e.getMessage());
throw new RuntimeException("pdf转换错误");
}
}
if (os != null) {
try {
os.close();
} catch (IOException e) {
log.error(e.getMessage());
throw new RuntimeException("pdf转换错误");
}
}
}
return dUrlData;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment