hlf 2 years ago
parent
commit
60f2eab93c

+ 5 - 15
ims-service/ims-eval/pom.xml

@@ -61,6 +61,11 @@
             <version>8.18.0</version>
         </dependency>
         <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.28</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.poi</groupId>
             <artifactId>poi</artifactId>
             <version>3.17-beta1</version>
@@ -70,21 +75,6 @@
             <artifactId>poi-ooxml</artifactId>
             <version>3.17-beta1</version>
         </dependency>
-        <dependency>
-            <groupId>org.freemarker</groupId>
-            <artifactId>freemarker</artifactId>
-            <version>2.3.28</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.pdfbox</groupId>
-            <artifactId>pdfbox</artifactId>
-            <version>2.0.4</version>
-        </dependency>
-        <dependency>
-            <groupId>fr.opensagres.xdocreport</groupId>
-            <artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
-            <version>2.0.1</version>
-        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 3 - 22
ims-service/ims-eval/src/main/java/com/ims/eval/controller/NoticeManagementController.java

@@ -10,13 +10,13 @@ import com.ims.eval.entity.custom.Path;
 import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.IDataDictionaryService;
 import com.ims.eval.service.IEvaluationNoticeService;
-import com.ims.eval.util.FileConvertUtil;
 import com.ims.eval.util.FileUploadUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -252,26 +252,7 @@ public class NoticeManagementController {
 	 * @throws IOException
 	 */
 	@GetMapping(value = "/filePreview")
-	public R filePreview(@RequestParam(value = "url") String url) {
-		File inputPath = new File(Path.getNoticePath() + url);
-		String prefix = url.substring(0, url.lastIndexOf(".") - 1);
-		String suffix = ".pdf";
-		String outputPath = Path.getNoticePath() + prefix + suffix;
-		try {
-			if (url.endsWith(".doc")) {
-				FileConvertUtil.convertDocToPdf(inputPath, outputPath);
-			} else if (url.endsWith(".docx")) {
-				FileConvertUtil.convertDocxToPdf(inputPath, outputPath);
-			} else if (url.endsWith(".xls")) {
-				FileConvertUtil.convertExcelToPdf(inputPath, outputPath);
-			} else if (url.endsWith(".xlsx")) {
-				FileConvertUtil.convertExcelToPdf(inputPath, outputPath);
-			} else {
-				throw new Exception("不支持的文件格式");
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return R.ok().data(outputPath);
+	public void filePreview(@RequestParam(value = "url") String url, HttpServletResponse response) throws IOException {
+		File inputFile = new File(Path.getNoticePath() + url);
 	}
 }

+ 0 - 82
ims-service/ims-eval/src/main/java/com/ims/eval/util/FileConvertUtil.java

@@ -1,82 +0,0 @@
-package com.ims.eval.util;
-
-import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.PDPageContentStream;
-import org.apache.pdfbox.pdmodel.font.PDType1Font;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
-
-import java.io.*;
-
-/**
- * @author hlf
- * @date 2023/5/25 17:45
- * 文件说明:
- */
-public class FileConvertUtil {
-
-	/**
-	 * 将 DOCX 文件转换为 PDF 格式并保存在上传路径下
-	 *
-	 * @param docxFile 需要转换的 DOCX 文件
-	 * @param pdfPath  转换生成的 PDF 文件在服务器中存放的路径
-	 * @throws IOException 抛出 IO 异常
-	 */
-	public static void convertDocxToPdf(File docxFile, String pdfPath) throws IOException {
-		try (InputStream inputStream = new FileInputStream(docxFile)) {
-			XWPFDocument document = new XWPFDocument(inputStream);
-			File targetFile = new File(pdfPath);
-			targetFile.getParentFile().mkdirs();
-			try (OutputStream outputStream = new FileOutputStream(targetFile)) {
-				PdfConverter.getInstance().convert(document, outputStream, null);
-			}
-		}
-	}
-
-	/**
-	 * 将 XLS、XLSX 文件转换为 PDF 格式并保存在上传路径下
-	 *
-	 * @param excelFile 需要转换的 Excel 文件对象
-	 * @param pdfPath   转换生成的 PDF 文件在服务器中存放的路径
-	 * @throws IOException 抛出 IO 异常
-	 */
-	public static void convertExcelToPdf(File excelFile, String pdfPath) throws IOException, InvalidFormatException {
-		try (InputStream inputStream = new FileInputStream(excelFile)) {
-			Workbook workbook = WorkbookFactory.create(inputStream);
-			PDDocument pdfDocument = new PDDocument();
-			for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
-				PDPage page = new PDPage();
-				pdfDocument.addPage(page);
-				PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page);
-				contentStream.beginText();
-				contentStream.setFont(PDType1Font.TIMES_BOLD, 12);
-				contentStream.setLeading(14.5f);
-				contentStream.newLineAtOffset(25, 725);
-				String[] sheetData = workbook.getSheetAt(i).getRow(0).toString().split(",");
-				for (String data : sheetData) {
-					contentStream.showText(data.trim());
-					contentStream.newLine();
-				}
-				contentStream.endText();
-				contentStream.close();
-			}
-			pdfDocument.save(pdfPath);
-			pdfDocument.close();
-		}
-	}
-
-	/**
-	 * 将 DOC 文件转换为 PDF 格式并保存在上传路径下
-	 *
-	 * @param docFile 需要转换的 DOC 文件对象
-	 * @param pdfPath 转换生成的 PDF 文件在服务器中存放的路径
-	 * @throws IOException 抛出 IO 异常
-	 */
-	public static void convertDocToPdf(File docFile, String pdfPath) throws IOException {
-		convertDocxToPdf(docFile, pdfPath);
-	}
-}