Document4j
08:38:17.340 [Thread-1] INFO c.d.c.m.MicrosoftWordBridge - [processLine,35] - �ܾ����ʡ� 08:38:17.365 [main] INFO c.d.c.m.MicrosoftWordBridge - [startUp,47] - From-Microsoft-Word-Converter was started successfully 08:38:17.380 [main] INFO c.d.j.LocalConverter - [
,54] - The documents4j local converter has started successfully 08:38:17.414 [pool-1-thread-1] INFO c.d.c.m.MicrosoftWordBridge - [doStartConversion,63] - Requested conversion from C:\Users\chongda\AppData\Local\Temp\77-0\aa386f6d-1fd7-4e2f-afbc-3a8095fdee29\temp1 (application/vnd.openxmlformats-officedocument.wordprocessingml.document) to C:\Users\chongda\AppData\Local\Temp\77-0\aa386f6d-1fd7-4e2f-afbc-3a8095fdee29\temp2 (application/pdf) 08:38:19.264 [Thread-4] INFO c.d.c.m.MicrosoftWordBridge - [processLine,35] - �ܾ����ʡ� com.documents4j.throwables.ConverterException: Conversion failed for an unknown reason at com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:90) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)


退出杀毒软件,或者关掉进程
pom.xml
<dependency> <groupId>com.documents4j
groupId> <artifactId>documents4j-local
artifactId> <version>1.1.1
version>
dependency> <dependency> <groupId>com.documents4j
groupId> <artifactId>documents4j-transformer-msoffice-word
artifactId> <version>1.1.1
version>
dependency>
word转pdf
/ * 本地资源转换pdf */ @CrossOrigin @GetMapping("/common/download/resourcePdf") public void resourceDownloadPdf(String resource, HttpServletRequest request, HttpServletResponse response) {
try {
resource = URLDecoder.decode(resource, "UTF-8"); if (!FileUtils.checkAllowDownload(resource)) {
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource)); } // 本地资源路径 String localPath = RuoYiConfig.getProfile(); // 数据库资源地址 String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); File inputWord = new File(downloadPath); File outputFile = new File(System.getProperty("user.dir") + "/uploadPath/pdf/" + downloadName.substring(0, downloadName.indexOf(".")) + ".pdf"); // 下载名称 InputStream docxInputStream = new FileInputStream(inputWord); OutputStream outputStream = new FileOutputStream(outputFile); IConverter converter = LocalConverter.builder().build(); converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute(); outputStream.close(); //返回转换之后的文件路径 FileInputStream in = new FileInputStream(outputFile.getPath()); response.setContentType(MediaType.APPLICATION_PDF_VALUE); OutputStream out = response.getOutputStream(); byte[] b = new byte[512]; while ((in.read(b)) != -1) {
out.write(b); } out.flush(); in.close(); out.close(); } catch (Exception e) {
log.error("文件转换失败", e); } }
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/207902.html原文链接:https://javaforall.net
