整理,pdf转换

beetlsql3-dev
Mlxa0324 2 years ago
parent 1dbe37812b
commit e37bc45d8a

@ -3,8 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>admin</artifactId>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>admin-framwork</artifactId>
<version>1.3.1</version> <version>1.3.1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -30,12 +30,13 @@
<artifactId>itextpdf</artifactId> <artifactId>itextpdf</artifactId>
<version>5.5.13.3</version> <version>5.5.13.3</version>
</dependency> </dependency>
<!--pdf依赖开始,导入本地依赖包crack jar-->
<dependency> <dependency>
<groupId>com.aspose</groupId> <groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId> <artifactId>aspose-words</artifactId>
<version>18.10</version> <version>18.10</version>
<classifier>jdk16</classifier> <scope>system</scope>
<systemPath></systemPath> <systemPath>${project.basedir}/src/main/resources/lib/aspose-words-18.10-jdk16.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.aspose</groupId> <groupId>com.aspose</groupId>
@ -45,7 +46,9 @@
<dependency> <dependency>
<groupId>com.aspose</groupId> <groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId> <artifactId>aspose-cells</artifactId>
<version>18.2</version> <version>20.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-cells-20.7.jar</systemPath>
</dependency> </dependency>
</dependencies> </dependencies>

@ -33,14 +33,16 @@ public final class PDFConverUtil {
final private static Map<TypeEnum, List<String>> types = new HashMap<>(); final private static Map<TypeEnum, List<String>> types = new HashMap<>();
public static enum TypeEnum { public static enum TypeEnum {
WORD, EXCEL, PPT, PPTX WORD, EXCEL, PPT, PPTX, OTHER
} }
static { static {
types.put(WORD, Arrays.asList("DOC", "DOCX", "OOXML", "RTF HTML", "OpenDocument", "PDF","EPUB", "XPS", "SWF")); types.put(WORD, Arrays.asList("DOC", "DOCX"));
types.put(EXCEL, Arrays.asList("XLS", "XLSX")); types.put(EXCEL, Arrays.asList("XLS", "XLSX"));
types.put(PPT, Arrays.asList("PPT")); types.put(PPT, Arrays.asList("PPT"));
types.put(PPTX, Arrays.asList("PPTX")); types.put(PPTX, Arrays.asList("PPTX"));
types.put(OTHER, Arrays.asList("OOXML", "RTF HTML", "OpenDocument", "PDF","EPUB", "XPS", "SWF"));
} }
/** /**
@ -95,13 +97,8 @@ public final class PDFConverUtil {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} finally { } finally {
try { closeOutput(outputStream);
if (document != null) { closeInput(inputStream);
document.close();
}
} catch (Exception e) {
e.printStackTrace();
}
} }
return true; return true;
@ -129,18 +126,50 @@ public final class PDFConverUtil {
e.printStackTrace(); e.printStackTrace();
return false; return false;
}finally { }finally {
if (outputStream != null) { closeOutput(outputStream);
try { closeInput(inputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
return true; return true;
} }
/**
*
* @param outputStream
*/
private static void closeOutput(OutputStream outputStream) {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
* @param inputStream
*/
private static void closeInput(InputStream inputStream) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void close(Document document, PdfWriter pdfWriter) {
if (document != null) {
document.close();
}
if (pdfWriter != null) {
pdfWriter.close();
}
}
// 官方文档的要求 无需理会 // 官方文档的要求 无需理会
public static boolean getLicense() { public static boolean getLicense() {
boolean result = false; boolean result = false;
@ -173,7 +202,7 @@ public final class PDFConverUtil {
**/ **/
public static boolean excelToPdf(InputStream inputStream, OutputStream outputStream) { public static boolean excelToPdf(InputStream inputStream, OutputStream outputStream) {
// 验证License 若不验证则转化出的pdf文档会有水印产生 // 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getExeclLicense()) { if (!getExcelLicense()) {
return false; return false;
} }
try { try {
@ -183,7 +212,6 @@ public final class PDFConverUtil {
com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(false); pdfSaveOptions.setOnePagePerSheet(false);
int[] autoDrawSheets={3}; int[] autoDrawSheets={3};
//当excel中对应的sheet页宽度太大时在PDF中会拆断并分页。此处等比缩放。 //当excel中对应的sheet页宽度太大时在PDF中会拆断并分页。此处等比缩放。
autoDraw(wb,autoDrawSheets); autoDraw(wb,autoDrawSheets);
@ -192,13 +220,14 @@ public final class PDFConverUtil {
//隐藏workbook中不需要的sheet页。 //隐藏workbook中不需要的sheet页。
printSheetPage(wb,showSheets); printSheetPage(wb,showSheets);
wb.save(outputStream, pdfSaveOptions); wb.save(outputStream, pdfSaveOptions);
outputStream.flush();
outputStream.close();
System.out.println("excel转换完毕"); System.out.println("excel转换完毕");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally {
closeOutput(outputStream);
closeInput(inputStream);
} }
return true; return true;
} }
@ -237,10 +266,21 @@ public final class PDFConverUtil {
} }
} }
public static boolean getExeclLicense() { public static boolean getExcelLicense() {
boolean result = false; boolean result = false;
try { try {
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>"; String s = "<License>\n" +
" <Data>\n" +
" <Products>\n" +
" <Product>Aspose.Cells for Java</Product>\n" +
" </Products>\n" +
" <EditionType>Enterprise</EditionType>\n" +
" <SubscriptionExpiry>29991231</SubscriptionExpiry>\n" +
" <LicenseExpiry>29991231</LicenseExpiry>\n" +
" <SerialNumber>evilrule</SerialNumber>\n" +
" </Data>\n" +
" <Signature>evilrule</Signature>\n" +
"</License>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes()); ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
com.aspose.cells.License aposeLic = new com.aspose.cells.License(); com.aspose.cells.License aposeLic = new com.aspose.cells.License();
aposeLic.setLicense(is); aposeLic.setLicense(is);
@ -284,11 +324,13 @@ public final class PDFConverUtil {
HSLFSlide hslfSlide = hslfSlideList.get(i); HSLFSlide hslfSlide = hslfSlideList.get(i);
// 设置字体, 解决中文乱码 // 设置字体, 解决中文乱码
for (HSLFShape shape : hslfSlide.getShapes()) { for (HSLFShape shape : hslfSlide.getShapes()) {
HSLFTextShape textShape = (HSLFTextShape) shape; if (shape instanceof HSLFTextShape) {
HSLFTextShape textShape = (HSLFTextShape) shape;
for (HSLFTextParagraph textParagraph : textShape.getTextParagraphs()) { for (HSLFTextParagraph textParagraph : textShape.getTextParagraphs()) {
for (HSLFTextRun textRun : textParagraph.getTextRuns()) { for (HSLFTextRun textRun : textParagraph.getTextRuns()) {
textRun.setFontFamily("宋体"); textRun.setFontFamily("宋体");
}
} }
} }
} }
@ -315,12 +357,9 @@ public final class PDFConverUtil {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} finally { } finally {
if (document != null) { close(document, pdfWriter);
document.close(); closeOutput(outputStream);
} closeInput(inputStream);
if (pdfWriter != null) {
pdfWriter.close();
}
} }
System.out.println("ppt转换完毕"); System.out.println("ppt转换完毕");
return true; return true;
@ -362,11 +401,13 @@ public final class PDFConverUtil {
// 设置字体, 解决中文乱码 // 设置字体, 解决中文乱码
for (XSLFShape shape : slide.getShapes()) { for (XSLFShape shape : slide.getShapes()) {
XSLFTextShape textShape = (XSLFTextShape) shape; if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
for (XSLFTextParagraph textParagraph : textShape.getTextParagraphs()) { for (XSLFTextParagraph textParagraph : textShape.getTextParagraphs()) {
for (XSLFTextRun textRun : textParagraph.getTextRuns()) { for (XSLFTextRun textRun : textParagraph.getTextRuns()) {
textRun.setFontFamily("宋体"); textRun.setFontFamily("宋体");
}
} }
} }
} }
@ -393,12 +434,9 @@ public final class PDFConverUtil {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} finally { } finally {
if (document != null) { close(document, pdfWriter);
document.close(); closeOutput(outputStream);
} closeInput(inputStream);
if (pdfWriter != null) {
pdfWriter.close();
}
} }
System.out.println("pptx转换完毕"); System.out.println("pptx转换完毕");
return true; return true;
@ -419,14 +457,17 @@ public final class PDFConverUtil {
if (types.get(WORD).contains(fileSuffix)) { if (types.get(WORD).contains(fileSuffix)) {
return wordToPdfByAspose(inputStream, outputStream); return wordToPdfByAspose(inputStream, outputStream);
} }
if (types.get(EXCEL).contains(fileSuffix)) {
return excelToPdf(inputStream, outputStream);
}
if (types.get(PPT).contains(fileSuffix)) { if (types.get(PPT).contains(fileSuffix)) {
return pptToPdf(inputStream, outputStream); return pptToPdf(inputStream, outputStream);
} }
if (types.get(PPTX).contains(fileSuffix)) { if (types.get(PPTX).contains(fileSuffix)) {
return pptxToPdf(inputStream, outputStream); return pptxToPdf(inputStream, outputStream);
} }
if (types.get(EXCEL).contains(fileSuffix)) { if (types.get(OTHER).contains(fileSuffix)) {
return excelToPdf(inputStream, outputStream); return wordToPdfByAspose(inputStream, outputStream);
} }
return false; return false;
} }

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>admin</artifactId>
<groupId>com.ibeetl</groupId>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibeetl</groupId>
<artifactId>admin-framwork</artifactId>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<modules>
<module>admin-convert-pdf</module>
</modules>
</project>

@ -1,10 +0,0 @@
### 学生列表
POST {{baseURL}}/jlw/student/list.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
###
GET {{baseURL}}/jlw/student/getValues.json?universitySystemId=1569331621092564992
Cookie: JSESSIONID={{session}}

@ -1,6 +0,0 @@
### 教师关联班级
POST {{baseURL}}/jlw/teacherOpenCourseMergeSchoolClass/add.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
schoolClassId=1&teacherOpenCourseId=1569699665614643200

@ -1,21 +0,0 @@
### 课程开课
POST {{baseURL}}/jlw/teacherOpenCourse/add.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
teacherId=2&teacherOpenCourseTitle={{$randomInt}}&teacherOpenCourseCode={{$randomInt}}&teacherOpenCourseCover=http://baidu.com&startTime=2022-09-12&endTime=2022-10-12
### 禁用开课的课程
POST {{baseURL}}/jlw/teacherOpenCourse/edit.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
# 打开开课的课程 teacherOpenCourseStatus=1
teacherOpenCourseId=1569699665614643200&teacherOpenCourseStatus=2
### 排课列表
POST {{baseURL}}/jlw/teacherOpenCourse/edit.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
# 打开开课的课程 teacherOpenCourseStatus=1
teacherOpenCourseId=1569699665614643200&teacherOpenCourseStatus=2

@ -1,19 +0,0 @@
### 教师发表评论
POST {{baseURL}}/jlw/teacherOpenCourseChatLog/add.json
Content-Type: application/json
Cookie: JSESSIONID={{session}}
{
"chatContent": "我是讨论的内容_{{$timestamp}}",
"keywords": "讨论,内容",
"schoolClassIds": "1,2",
"teacherId": "2",
"teacherOpenCourseId": "1569699665614643200"
}
### 教师开课互动
POST {{baseURL}}/jlw/teacherOpenCourseChatLog/details.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
teacherOpenCourseChatLogParentId=1571525020268797952

@ -1,25 +0,0 @@
### 新增作业
POST {{baseURL}}/jlw/teacherOpenCourseQuestion/addByType.json
Content-Type: application/json
Cookie: JSESSIONID={{session}}
{
"teacherOpenCourseId": 59,
"teacherOpenCourseQuestionName": "fake_data",
"teacherOpenCourseQuestionClasses": "2",
"teacherOpenCourseQuestionStartTime": "2018-12-08 12:40:39",
"teacherOpenCourseQuestionEndTime": "2031-08-02 15:28:09",
"teacherOpenCourseQuestionType": "QUESTION",
"teacherOpenCourseQuestionUploadFile": "fake_data",
"teacherOpenCourseQuestionPushStatus": 1,
"teacherOpenCourseQuestionStatus": 1,
"teacherOpenCourseQuestionAddTime": "2023-12-06 19:10:09",
"teacherOpenCourseQuestionSettingQuery": {
"teacherOpenCourseQuestionSettingDoCount": 10,
"teacherOpenCourseQuestionSettingQuestionNoOrder": 1,
"teacherOpenCourseQuestionSettingOptionNoOrder": 1,
"teacherOpenCourseQuestionSettingEndShowQa": 1,
"teacherOpenCourseQuestionSettingEndShowTrueFalse": 1,
"teacherOpenCourseQuestionSettingAddTime": "2022-05-25 03:23:43"
}
}

@ -1,63 +0,0 @@
### 学校管理员--新增排课
POST {{baseURL}}/jlw/teacherOpenCourseScheduleSession/addSession.json
Content-Type: application/json
Cookie: JSESSIONID={{session}}
//{
// "startTime": "2022-10-25",
// "weekNum": "3",
// "openOnHolidays": false,
// "weekDetail": [
// "T1",
// "T2",
// "T3",
// "T4",
// "T5"
// ],
// "schoolClassIdPlural": "5,11,8",
// "teacherId": "1",
// "teacherOpenCourseId": "1569",
// "sessionClassList": {
// "1568607566282530816": [
// 1568633666106728448,
// 1568634328282472448,
// 1568634328282472448
// ],
// "1568621132431663104": [
// 1586024846784110592,
// 1586025166549458944
// ]
// }
//}
{
"startTime": "2022-10-25",
"weekNum": "4",
"openOnHolidays": false,
"weekDetail": [
"T1",
"T2",
"T3",
"T4"
],
"schoolClassIdPlural": "12,13,14,7,9",
"teacherId": "102",
"teacherOpenCourseId": "10086",
"sessionClassList": {
"1568607566282530816": [
1586025337723199488
],
"1568621132431663104": [
1586025244957777920
]
}
}
### 排课列表
POST {{baseURL}}/jlw/teacherOpenCourseScheduleSession/groupList.json
Content-Type: application/x-www-form-urlencoded
Cookie: JSESSIONID={{session}}
# 可以带TeacherOpenCourseScheduleSessionQuery 里的查询参数

@ -1,6 +0,0 @@
{
"dev": {
"baseURL": "http://localhost:9090/server/",
"session": "4DF96B3C791C90F8696C81F5EED4F81C"
}
}

@ -19,7 +19,7 @@
<module>admin-console</module> <module>admin-console</module>
<module>web</module> <module>web</module>
<module>admin-test</module> <module>admin-test</module>
<module>admin-convert-pdf</module> <module>admin-framework</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>

@ -21,10 +21,10 @@
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>admin-core</artifactId> <artifactId>admin-core</artifactId>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>com.ibeetl</groupId>--> <groupId>com.ibeetl</groupId>
<!-- <artifactId>admin-convert-pdf</artifactId>--> <artifactId>admin-convert-pdf</artifactId>
<!-- </dependency>--> </dependency>
<!-- admin-console 包含了系统管理管理的所有功能,子系统可以不使用这部分 --> <!-- admin-console 包含了系统管理管理的所有功能,子系统可以不使用这部分 -->
<dependency> <dependency>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>

@ -1,13 +1,17 @@
package com.ibeetl.jlw.web; package com.ibeetl.jlw.web;
import cn.hutool.core.io.FileUtil;
import cn.jlw.Interceptor.RFile; import cn.jlw.Interceptor.RFile;
import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.jlw.entity.FileEntity; import com.ibeetl.jlw.entity.FileEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import util.convertPDF.PDFConverUtil;
import java.io.BufferedInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -76,12 +80,16 @@ public class TempFileController {
//fileEntity.moveTo("D://"); //fileEntity.moveTo("D://");
//相对路径 //相对路径
//fileEntity.moveTo("/image"); //fileEntity.moveTo("/image");
// if (null != fileEntity) { if (null != fileEntity) {
// String absoluteUrl = fileEntity.getAbsoluteUrl(); String absoluteUrl = fileEntity.getAbsoluteUrl();
// BufferedInputStream inputStream = FileUtil.getInputStream(absoluteUrl); BufferedInputStream inputStream = FileUtil.getInputStream(absoluteUrl);
// FileOutputStream outputStream = new FileOutputStream(absoluteUrl.replaceAll("\\.[^\\.]+", ".pdf")); String pdfName = absoluteUrl.replaceAll("\\.[^\\.]+", ".pdf");
// PDFConverUtil.convertToPDFByFileNameSuffix(absoluteUrl, inputStream, outputStream); FileOutputStream outputStream = new FileOutputStream(pdfName);
// } boolean convertedSuccess = PDFConverUtil.convertToPDFByFileNameSuffix(absoluteUrl, inputStream, outputStream);
if(convertedSuccess) {
fileEntity.set("cvPDFAbsoluteUrl", pdfName);
}
}
return JsonResult.success(fileEntity); return JsonResult.success(fileEntity);
//return JsonResult.success(); //return JsonResult.success();

Loading…
Cancel
Save