Commit 10b8164a authored by chase's avatar chase

merge 档案管理

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