|
|
@@ -10,14 +10,13 @@ import cn.seecoder.seecoderportalserver.repository.CourseRepository;
|
|
|
import cn.seecoder.seecoderportalserver.repository.CourseWareRepository;
|
|
|
import cn.seecoder.seecoderportalserver.service.CourseWareService;
|
|
|
import cn.seecoder.seecoderportalserver.utility.OssUtil;
|
|
|
-import com.itextpdf.text.Document;
|
|
|
-import com.itextpdf.text.Image;
|
|
|
-import com.itextpdf.text.pdf.PdfPCell;
|
|
|
-import com.itextpdf.text.pdf.PdfPTable;
|
|
|
-import com.itextpdf.text.pdf.PdfWriter;
|
|
|
+//import com.itextpdf.text.Document;
|
|
|
+//import com.itextpdf.text.Image;
|
|
|
+//import com.itextpdf.text.pdf.PdfPCell;
|
|
|
+//import com.itextpdf.text.pdf.PdfPTable;
|
|
|
+//import com.itextpdf.text.pdf.PdfWriter;
|
|
|
//import org.apache.poi.hslf.usermodel.*;
|
|
|
//import org.apache.poi.xslf.usermodel.*;
|
|
|
-import org.apache.poi.hslf.usermodel.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -113,74 +112,74 @@ public class CourseWareServiceImpl implements CourseWareService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static boolean pptToPdf(InputStream inputStream, OutputStream outputStream) {
|
|
|
-
|
|
|
- Document document = null;
|
|
|
- HSLFSlideShow hslfSlideShow = null;
|
|
|
- PdfWriter pdfWriter = null;
|
|
|
-
|
|
|
- try {
|
|
|
- hslfSlideShow = new HSLFSlideShow(inputStream);
|
|
|
-
|
|
|
- // 获取ppt文件页面
|
|
|
- Dimension dimension = hslfSlideShow.getPageSize();
|
|
|
-
|
|
|
- document = new Document();
|
|
|
-
|
|
|
- // pdfWriter实例
|
|
|
- pdfWriter = PdfWriter.getInstance(document, outputStream);
|
|
|
-
|
|
|
- document.open();
|
|
|
-
|
|
|
- PdfPTable pdfPTable = new PdfPTable(1);
|
|
|
-
|
|
|
- List<HSLFSlide> hslfSlideList = hslfSlideShow.getSlides();
|
|
|
-
|
|
|
- for (int i=0; i < hslfSlideList.size(); i++) {
|
|
|
- HSLFSlide hslfSlide = hslfSlideList.get(i);
|
|
|
-// // 设置字体, 解决中文乱码
|
|
|
-// for (HSLFShape shape : hslfSlide.getShapes()) {
|
|
|
-// HSLFTextShape textShape = (HSLFTextShape) shape;
|
|
|
+// public static boolean pptToPdf(InputStream inputStream, OutputStream outputStream) {
|
|
|
//
|
|
|
-// for (HSLFTextParagraph textParagraph : textShape.getTextParagraphs()) {
|
|
|
-// for (HSLFTextRun textRun : textParagraph.getTextRuns()) {
|
|
|
-// textRun.setFontFamily("宋体");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- BufferedImage bufferedImage = new BufferedImage((int)dimension.getWidth(), (int)dimension.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
|
-
|
|
|
- Graphics2D graphics2d = bufferedImage.createGraphics();
|
|
|
-
|
|
|
- graphics2d.setPaint(Color.white);
|
|
|
- graphics2d.setFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 12));
|
|
|
-
|
|
|
- hslfSlide.draw(graphics2d);
|
|
|
-
|
|
|
- graphics2d.dispose();
|
|
|
-
|
|
|
- Image image = Image.getInstance(bufferedImage, null);
|
|
|
- image.scalePercent(50f);
|
|
|
-
|
|
|
- // 写入单元格
|
|
|
- pdfPTable.addCell(new PdfPCell(image, true));
|
|
|
- document.add(image);
|
|
|
-
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- } finally {
|
|
|
- if (document != null) {
|
|
|
- document.close();
|
|
|
- }
|
|
|
- if (pdfWriter != null) {
|
|
|
- pdfWriter.close();
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println("ppt转换完毕");
|
|
|
- return true;
|
|
|
- }
|
|
|
+// Document document = null;
|
|
|
+// HSLFSlideShow hslfSlideShow = null;
|
|
|
+// PdfWriter pdfWriter = null;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// hslfSlideShow = new HSLFSlideShow(inputStream);
|
|
|
+//
|
|
|
+// // 获取ppt文件页面
|
|
|
+// Dimension dimension = hslfSlideShow.getPageSize();
|
|
|
+//
|
|
|
+// document = new Document();
|
|
|
+//
|
|
|
+// // pdfWriter实例
|
|
|
+// pdfWriter = PdfWriter.getInstance(document, outputStream);
|
|
|
+//
|
|
|
+// document.open();
|
|
|
+//
|
|
|
+// PdfPTable pdfPTable = new PdfPTable(1);
|
|
|
+//
|
|
|
+// List<HSLFSlide> hslfSlideList = hslfSlideShow.getSlides();
|
|
|
+//
|
|
|
+// for (int i=0; i < hslfSlideList.size(); i++) {
|
|
|
+// HSLFSlide hslfSlide = hslfSlideList.get(i);
|
|
|
+//// // 设置字体, 解决中文乱码
|
|
|
+//// for (HSLFShape shape : hslfSlide.getShapes()) {
|
|
|
+//// HSLFTextShape textShape = (HSLFTextShape) shape;
|
|
|
+////
|
|
|
+//// for (HSLFTextParagraph textParagraph : textShape.getTextParagraphs()) {
|
|
|
+//// for (HSLFTextRun textRun : textParagraph.getTextRuns()) {
|
|
|
+//// textRun.setFontFamily("宋体");
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+// BufferedImage bufferedImage = new BufferedImage((int)dimension.getWidth(), (int)dimension.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
|
+//
|
|
|
+// Graphics2D graphics2d = bufferedImage.createGraphics();
|
|
|
+//
|
|
|
+// graphics2d.setPaint(Color.white);
|
|
|
+// graphics2d.setFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 12));
|
|
|
+//
|
|
|
+// hslfSlide.draw(graphics2d);
|
|
|
+//
|
|
|
+// graphics2d.dispose();
|
|
|
+//
|
|
|
+// Image image = Image.getInstance(bufferedImage, null);
|
|
|
+// image.scalePercent(50f);
|
|
|
+//
|
|
|
+// // 写入单元格
|
|
|
+// pdfPTable.addCell(new PdfPCell(image, true));
|
|
|
+// document.add(image);
|
|
|
+//
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// return false;
|
|
|
+// } finally {
|
|
|
+// if (document != null) {
|
|
|
+// document.close();
|
|
|
+// }
|
|
|
+// if (pdfWriter != null) {
|
|
|
+// pdfWriter.close();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// System.out.println("ppt转换完毕");
|
|
|
+// return true;
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public String changeCourseWareName(Long id, String newName) {
|