Commit 10b8164a authored by chase's avatar chase

merge 档案管理

parent 424abbe6
...@@ -115,8 +115,9 @@ public class TaxDocumentController { ...@@ -115,8 +115,9 @@ public class TaxDocumentController {
*/ */
@PostMapping("/previewPDF") @PostMapping("/previewPDF")
@ResponseBody @ResponseBody
public String previewPDF(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) { public void previewPDF(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) {
return taxDocumentService.previewPDF2(response,taxDocumentDto.getPath()); // return taxDocumentService.previewPDF2(response,taxDocumentDto.getPath());
taxDocumentService.previewPDF(response,taxDocumentDto.getPath());
/*InputStream is = null; /*InputStream is = null;
ByteArrayOutputStream os = null; ByteArrayOutputStream os = null;
try { try {
......
...@@ -438,8 +438,10 @@ public class TaxDocumentServiceImpl { ...@@ -438,8 +438,10 @@ public class TaxDocumentServiceImpl {
try { try {
sos = response.getOutputStream(); sos = response.getOutputStream();
PDFToImg(sos, path, getPDFNum(path), imageType); PDFToImg(sos, path, getPDFNum(path), imageType);
} catch (IOException e) { sos.flush();
} catch (Exception e) {
log.error("PDF转换图片异常: " + e.getMessage()); log.error("PDF转换图片异常: " + e.getMessage());
throw new RuntimeException("PDF转换异常");
} finally { } finally {
try { try {
sos.close(); sos.close();
...@@ -1162,7 +1164,7 @@ public class TaxDocumentServiceImpl { ...@@ -1162,7 +1164,7 @@ public class TaxDocumentServiceImpl {
* @throws IOException * @throws IOException
* imgType:转换后的图片类型 jpg,png * imgType:转换后的图片类型 jpg,png
*/ */
private void PDFToImg(OutputStream sos,String fileUrl,int page,String imgType) throws IOException { private void PDFToImg(OutputStream sos,String fileUrl,int page,String imgType) throws Exception {
PDDocument pdDocument = null; PDDocument pdDocument = null;
/* dpi越大转换后越清晰,相对转换速度越慢 */ /* dpi越大转换后越清晰,相对转换速度越慢 */
int dpi = 100; int dpi = 100;
...@@ -1171,12 +1173,13 @@ public class TaxDocumentServiceImpl { ...@@ -1171,12 +1173,13 @@ public class TaxDocumentServiceImpl {
PDFRenderer renderer = new PDFRenderer(pdDocument); PDFRenderer renderer = new PDFRenderer(pdDocument);
int pages = pdDocument.getNumberOfPages(); int pages = pdDocument.getNumberOfPages();
if (page <= pages && page > 0) { if (page <= pages && page > 0) {
BufferedImage image = renderer.renderImageWithDPI(page,dpi); BufferedImage image = renderer.renderImageWithDPI(page-1,dpi);
ImageIO.write(image, imgType, sos); ImageIO.write(image, imgType, sos);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage(),e); log.error(e.getMessage(),e);
throw new RuntimeException("PDF转换异常");
} finally { } finally {
if (pdDocument != null) { if (pdDocument != null) {
pdDocument.close(); pdDocument.close();
......
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