springboot2,mysql基础知识于面试

org.springframework.boot

spring-boot-maven-plugin

true

4.添加配置文件license.xml到resources下

<?xml version="1.0" encoding="UTF-8" ?>

Aspose.Total for Java

Aspose.Words for Java

Enterprise

20991231

20991231

8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7

sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=

5.工具类如下

import com.aspose.words.Document;

import com.aspose.words.ImageSaveOptions;

import com.aspose.words.License;

import com.aspose.words.SaveFormat;

import lombok.extern.slf4j.Slf4j;

import java.io.File;

import java.io.FileOutputStream;

import java.io.InputStream;

/**

  • @author Administrator

  • @version I d Id Id

  • @see

  • @since

*/

@Slf4j

public class Word2PdfUtil {

public static String inPath = “D:\upload\test1.docx”;

public static String outDir = “D:\upload\”;

public static void main(String[] args) {

doc2Img(inPath,outDir);

}

public static boolean getLicense() {

boolean result = false;

try {

// license.xml应放在…\WebRoot\WEB-INF\classes路径下

InputStream is = Word2PdfUtil.class.getClassLoader().getResourceAsStream(“license.xml”);

License aposeLic = new License();

aposeLic.setLicense(is);

result = true;

} catch (Exception e) {

e.printStackTrace();

}

return result;

}

/**

  • 文档转图片

  • @param inPath 传入文档地址

  • @param outDir 输出的图片文件夹地址

*/

public static void doc2Img(String inPath, String outDir) {

try {

if (!getLicense()) {

throw new Exception(“com.aspose.words lic ERROR!”);

}

log.info(inPath + " -> " + outDir);

long old = System.currentTimeMillis();

// word文档

Document doc = new Document(inPath);

// 支持RTF HTML,OpenDocument, PDF,EPUB, XPS

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

转换

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);

int pageCount = doc.getPageCount();

for (int i = 0; i < pageCount; i++) {

File file = new File(outDir + “/” + i + “.png”);

log.info(outDir + “/” + i + “.png”);

FileOutputStream os = new FileOutputStream(file);

options.setPageIndex(i);

doc.save(os, options);

os.close();

}

long now = System.currentTimeMillis();

log.info("convert OK! " + ((now - old) / 1000.0) + “秒”);

} catch (Exception e) {

e.printStackTrace();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值