赞
踩
目录
ps:
引入后启动项目控制台可能会打印红色警告:
SLF4J: Class path contains multiple SLF4J bindings.
如果你出现了这个问题,不要慌。出错的原因可能不一样,exclusion写法也会不一样。解决方法放在另外一篇文章了:解决SLF4J: Class path contains multiple SLF4J bindings.
- <dependency>
- <groupId>org.ofdrw</groupId>
- <artifactId>ofdrw-converter</artifactId>
- <version>1.17.9</version>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- public class TestOfd2Pdf {
- // 测试比较简单的转换方式
- public static void main(String[] args) {
- File ofdFile = new File("E:\\044002000311_72262900.ofd");
- Path pdfPath = Paths.get("E:\\1.pdf");
- ConvertHelper.toPdf(ofdFile.toPath(), pdfPath);
- }
- }
ps:
byte[]、File、Path等之间的转换。
- public File convertOFD2PDF(String bucketName, String fileName, String filePdfPath) {
- byte[] bytes = downloadUseBytes(bucketName, fileName).get("fileBytes");
- String ofdFileName = "/toPdf" + System.currentTimeMillis() + ".ofd";
- File ofdFile = FileUtils.writeBytes(bytes,
- FileUtils.createTempFile(ofdFileName, true));
- Path ofdPath = ofdFile.toPath();
- Path pdfPath = Paths.get(filePdfPath);
- ConvertHelper.toPdf(ofdPath, pdfPath);
- ofdFile.delete(); // 临时ofd文件使用完后删除
- return pdfPath.toFile();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。