pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/ProductBomApprovingService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/util/DwgToPdfUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/util/Word2PdfAsposeUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
pom.xml
@@ -193,6 +193,13 @@ <scope>system</scope> <systemPath>${pom.basedir}/src/main/resources/lib/aspose-cad-22.3-jdk16.jar</systemPath> </dependency> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-words</artifactId> <version>22.3</version> <scope>system</scope> <systemPath>${pom.basedir}/src/main/resources/lib/aspose-words-22.3-jdk16.jar</systemPath> </dependency> </dependencies> <build> src/main/java/com/whyc/service/ProductBomApprovingService.java
@@ -389,20 +389,39 @@ return list; } /** * * @param dwgUrl 预览dwg图纸文件,后追加预览word文档 * @return * @throws IOException */ public Response dwgReview(String dwgUrl) throws IOException { String fileSuffix = dwgUrl.substring(dwgUrl.lastIndexOf(".") + 1); //绝对路径xxx/doc_file String rootFile = CommonUtil.getRootFile(); String dwgSubFilePath = dwgUrl.substring(dwgUrl.indexOf("doc_file")+8); String dwgSubFileDirPath = dwgSubFilePath.substring(0,dwgSubFilePath.lastIndexOf(File.separator)); File dwgFile = new File(rootFile + dwgSubFilePath); String dwgPdfUrl = dwgFile.getParent() + File.separator + dwgFile.getName().substring(0, dwgFile.getName().lastIndexOf(".")) + "-dwg.pdf"; File dwgPdfFile = new File(dwgPdfUrl); String pdfFileName = null; if(!dwgPdfFile.exists()) { pdfFileName = DwgToPdfUtil.dwg2Pdf(dwgFile); }else{ pdfFileName = dwgPdfFile.getName(); String pdfUrl = ""; if(fileSuffix.equals("dwg")) { pdfUrl = dwgFile.getParent() + File.separator + dwgFile.getName().substring(0, dwgFile.getName().lastIndexOf(".")) + "-dwg.pdf"; }else if(fileSuffix.contains("doc")){ pdfUrl = dwgFile.getParent() + File.separator + dwgFile.getName().substring(0, dwgFile.getName().lastIndexOf(".")) + "-doc.pdf"; } File pdfFile = new File(pdfUrl); String pdfFileName = null; if(!pdfFile.exists()) { if(fileSuffix.equals("dwg")) { //pdfFileName = DwgToPdfUtil.dwg2Pdf(dwgFile); DwgToPdfUtil.dwg2Pdf(dwgFile); }else if(fileSuffix.contains("doc")){ Word2PdfAsposeUtil.doc2pdf(dwgFile.getAbsolutePath(),pdfUrl); } }/*else{ pdfFileName = pdfFile.getName(); }*/ pdfFileName = pdfFile.getName(); return new Response().set(1,"doc_file"+dwgSubFileDirPath+File.separator+pdfFileName); } src/main/java/com/whyc/util/DwgToPdfUtil.java
@@ -4,9 +4,7 @@ import com.aspose.cad.Image; import com.aspose.cad.imageoptions.CadRasterizationOptions; import com.aspose.cad.imageoptions.PdfOptions; import com.aspose.cad.internal.J.F; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.io.File; import java.io.FileInputStream; @@ -46,7 +44,7 @@ } finally { fileInputStream.close(); } log.info("文件转换成功{}",dwgFile.getName()); //log.info("文件转换成功{}",dwgFile.getName()); return outputFile.getName(); } src/main/java/com/whyc/util/Word2PdfAsposeUtil.java
New file @@ -0,0 +1,52 @@ package com.whyc.util; import com.aspose.words.Document; import com.aspose.words.SaveFormat; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Word2PdfAsposeUtil { /**去除水印专用*/ /*public static boolean getLicense() { boolean result = false; try { InputStream is = Test.class.getClassLoader().getResourceAsStream("\\license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下 License aposeLic = new License(); aposeLic.setLicense(is); result = true; } catch (Exception e) { e.printStackTrace(); } return result; }*/ public static boolean doc2pdf(String inPath, String outPath) { /*if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生 return false; }*/ FileOutputStream os = null; try { File file = new File(outPath); // 新建一个空白pdf文档 os = new FileOutputStream(file); Document doc = new Document(inPath); // Address是将要被转化的word文档 doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, } catch (Exception e) { e.printStackTrace(); return false; }finally { if (os != null) { try { os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; } }