|
|
@@ -19,6 +19,8 @@ import freemarker.template.Template;
|
|
|
import freemarker.template.Version;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.pdfbox.io.MemoryUsageSetting;
|
|
|
+import org.apache.pdfbox.multipdf.PDFMergerUtility;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -29,6 +31,13 @@ import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
+
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@AllArgsConstructor
|
|
|
@@ -150,12 +159,12 @@ public class RateService {
|
|
|
.stream();
|
|
|
files.add(stream);
|
|
|
this.downloadFile1(files, rate.getPrivacyPolicy());
|
|
|
-// this.downloadFile(files, rate.getBusiness(), "业务内容");
|
|
|
-// this.downloadFile(files, rate.getCredits(), "社会信誉");
|
|
|
-// this.downloadFile(files, rate.getFire(), "消防安全");
|
|
|
-// this.downloadFile(files, rate.getHygiene(), "卫生防疫");
|
|
|
-// this.downloadFile(files, rate.getFinance(), "财务报表");
|
|
|
-// this.downloadFile(files, rate.getProperty(), "房产证明");
|
|
|
+ this.downloadFile1(files, rate.getBusiness());
|
|
|
+ this.downloadFile1(files, rate.getCredits());
|
|
|
+ this.downloadFile1(files, rate.getFire());
|
|
|
+ this.downloadFile1(files, rate.getHygiene());
|
|
|
+ this.downloadFile1(files, rate.getFinance());
|
|
|
+ this.downloadFile1(files, rate.getProperty());
|
|
|
return files;
|
|
|
}
|
|
|
|
|
|
@@ -172,8 +181,7 @@ public class RateService {
|
|
|
.stream();
|
|
|
files.add(stream);
|
|
|
} else if (getSuffix(privacy).equals("pdf")) {
|
|
|
- InputStream stream = HttpRequest.get(privacy)
|
|
|
- .stream();
|
|
|
+ InputStream stream = HttpRequest.get(privacy).stream();
|
|
|
files.add(stream);
|
|
|
}
|
|
|
});
|
|
|
@@ -185,16 +193,14 @@ public class RateService {
|
|
|
num.getAndIncrement();
|
|
|
File file1 = new File("/Users/qiufangchao/Desktop/" + filename + num + ".pdf");
|
|
|
if (getSuffix(privacy).equals("doc") || getSuffix(privacy).equals("docx")) {
|
|
|
- InputStream is1 = HttpRequest.get(privacy)
|
|
|
- .stream();
|
|
|
+ InputStream is1 = HttpRequest.get(privacy).stream();
|
|
|
HttpRequest.post("http://192.168.50.238:8080/word2pdf")
|
|
|
.accept("*/*")
|
|
|
.part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is1)
|
|
|
.receive(file1);
|
|
|
files.add(file1);
|
|
|
} else if (getSuffix(privacy).equals("pdf")) {
|
|
|
- HttpRequest.get(privacy)
|
|
|
- .receive(file1);
|
|
|
+ HttpRequest.get(privacy).receive(file1);
|
|
|
files.add(file1);
|
|
|
}
|
|
|
});
|
|
|
@@ -207,4 +213,37 @@ public class RateService {
|
|
|
}
|
|
|
return url.substring(index + 1);
|
|
|
}
|
|
|
+
|
|
|
+ public void exportPdf(Long id, HttpServletResponse response) throws IOException {
|
|
|
+ Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
+ List<InputStream> files = this.upLoad1(rate);
|
|
|
+
|
|
|
+ // pdf合并工具类
|
|
|
+ PDFMergerUtility mergePdf = new PDFMergerUtility();
|
|
|
+ mergePdf.addSources(files);
|
|
|
+
|
|
|
+ // 指定目标文件输出流
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ mergePdf.setDestinationStream(outputStream);
|
|
|
+
|
|
|
+ mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
|
|
|
+
|
|
|
+ // 设置合并生成pdf文件名称
|
|
|
+// String targetPath = "/Users/qiufangchao/Desktop/result.pdf";
|
|
|
+// mergePdf.setDestinationFileName(targetPath);
|
|
|
+
|
|
|
+ for (InputStream is : files) {
|
|
|
+ is.close();
|
|
|
+ }
|
|
|
+// return outputStream.toString();
|
|
|
+
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + "result.pdf");
|
|
|
+
|
|
|
+ ServletOutputStream sos = response.getOutputStream();
|
|
|
+ sos.write(outputStream.toByteArray());
|
|
|
+
|
|
|
+ sos.flush();
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
}
|