xiexiang пре 1 година
родитељ
комит
d5849a0f59

+ 40 - 5
src/main/java/cn/cslg/pas/service/business/PDFExportFirstPageService.java

@@ -22,6 +22,10 @@ import org.apache.pdfbox.multipdf.PDFMergerUtility;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -94,6 +98,11 @@ public class PDFExportFirstPageService {
                             String pdfGuid2 = FormatUtil.getPDFFormat(appNo, type2);
                             pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid2);
                             if (pdfData == null || pdfData.length == 0) {
+                                // 创建一个空白页文档 内容为暂无文档
+                                PDDocument blankPageDocument = createBlankPageDocument();
+                                merger.appendDocument(resultDocument, blankPageDocument);
+                                // 不需要关闭 blankPageDocument,因为在保存 resultDocument 时会处理它
+                                // 同样,根据这个修改更新任何相关的 WebSocketMessageVO 或代码其他部分。
                                 defaultNum++;
                                 continue;
                             } else {
@@ -169,11 +178,7 @@ public class PDFExportFirstPageService {
         messageService.sendPDFExportMessage(webSocketMessageVO);
         String fileGuid = "";
         if (out.toByteArray() != null && out.toByteArray().length != 0) {
-            if (defaultNum != total) {
-                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 2);
-            } else {
-                throw new XiaoShiException("无成功条数");
-            }
+            fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 2);
         }
         exportTask.setFileGuid(fileGuid);
         exportTask.setAllNum(total);
@@ -187,6 +192,36 @@ public class PDFExportFirstPageService {
     }
 
     /**
+     * 创建一个空白pdf文档 内容为”暂无文档“
+     * @return
+     * @throws IOException
+     */
+    private PDDocument createBlankPageDocument() throws IOException {
+        PDDocument document = new PDDocument();
+        PDPage blankPage = new PDPage();
+        document.addPage(blankPage);
+
+        try (PDPageContentStream contentStream = new PDPageContentStream(document, blankPage)) {
+            // 加载适当的字体
+            PDFont font = PDType1Font.HELVETICA_BOLD;
+            contentStream.setFont(font, 30);
+
+            String text = "NO DOCUMENTS";
+            float textWidth = font.getStringWidth(text) / 1000 * 30;
+            PDRectangle pageSize = blankPage.getMediaBox();
+            float startX = (pageSize.getWidth() - textWidth) / 2;
+            float startY = pageSize.getHeight() / 2;
+
+            //居中
+            contentStream.beginText();
+//            contentStream.setLeading(14.5f);
+            contentStream.newLineAtOffset(startX, startY);
+            contentStream.showText(text);
+            contentStream.endText();
+        }
+        return document;
+    }
+    /**
      * 获取专利号
      * @param EsVO
      * @return