|
|
@@ -8,12 +8,15 @@ import com.uas.report.util.FileUtils;
|
|
|
import com.uas.report.util.ReportUtils;
|
|
|
import net.sf.jasperreports.engine.JRException;
|
|
|
import org.dom4j.DocumentException;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
@@ -228,6 +231,8 @@ public class PdfController {
|
|
|
fileService.rangeDownload(file, n == null ? null : n + "."+ExportType.PDF.getQualifier(), request, response);
|
|
|
}
|
|
|
|
|
|
+ private Logger logger= LoggerFactory.getLogger(PdfController.class);
|
|
|
+
|
|
|
/**
|
|
|
* 预览 pdf (Content Type 为 application/pdf)
|
|
|
*
|
|
|
@@ -244,6 +249,27 @@ public class PdfController {
|
|
|
if(!file.getName().toLowerCase().endsWith(".pdf")){
|
|
|
throw new IOException("并非 pdf 文件:" + p);
|
|
|
}
|
|
|
- fileService.rangeDownloadWithContentType(file, "application/pdf", request, response);
|
|
|
+ FileInputStream fis = new FileInputStream(file);
|
|
|
+
|
|
|
+ try {
|
|
|
+ response.setHeader("Content-Length", file.length() + "");
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ byte[] data = new byte[1024];
|
|
|
+ int i;
|
|
|
+ int count = 0;
|
|
|
+ try {
|
|
|
+ while (count <= file.length() && (i = fis.read(data)) != -1) {
|
|
|
+ outputStream.write(data, 0, i);
|
|
|
+ count += i;
|
|
|
+ }
|
|
|
+ outputStream.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ fis.close();
|
|
|
+ }
|
|
|
}
|
|
|
}
|