当前位置: 首页> 财经> 访谈 > java对word文档转图片,转PDF

java对word文档转图片,转PDF

时间:2025/7/10 18:25:38来源:https://blog.csdn.net/new_public/article/details/140004086 浏览次数:0次

话不多说,直接入题


先引包

        <dependency><groupId>com.luhuiguo</groupId><artifactId>aspose-words</artifactId><version>23.1</version></dependency>

word文档转图片

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;/*** word文档转图片* @param wordPath word文档路径* @param outImgPath 图片输出路径*/public static void wordConvertImg(String wordPath, String outImgPath) {try(FileInputStream fileInputStream = new FileInputStream(wordPath);) {Document document = new Document(fileInputStream);// 只转第一页,如果有多页,这里得循环一下Document page = document.extractPages(0, 1);page.save(outImgPath, SaveFormat.PNG);} catch (Exception e) {log.error("word文档转图片错误", e);throw new RuntimeException(e);}}

word文档转PDF

 

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;/*** word文档转PDF* @param wordPath word文档路径* @param outPdfPath PDF输出路径*/public static void wordConvertImg(String wordPath, String outPdfPath) {try(FileInputStream fileInputStream = new FileInputStream(wordPath);FileOutputStream pdfOutStremp = new FileOutputStream(outPdfPath);) {Document document = new Document(fileInputStream);document.save(pdfOutStremp, SaveFormat.PDF);} catch (Exception e) {log.error("word文档转PDF错误", e);throw new RuntimeException(e);}}

码字不易,于你有利,勿忘点赞

关键字:java对word文档转图片,转PDF

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: