背景:安卓手机没办法预览标题的几个基本文件类型,只能先转成图片之后再上传至阿里云。这边使用了aspose上传。
一、引入jar依赖

链接: https://pan.baidu.com/s/1IGQMRj6XSgtsUpz7oQNdyA 提取码: 53cy 复制这段内容后打开百度网盘手机App,操作更方便哦
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.8.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-words-15.8.0-jdk16.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>8.5.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-cells-8.5.2.jar</systemPath>
</dependency>
<dependency>
<groupId>aspose.slides</groupId>
<artifactId>slides</artifactId>
<version>15.9.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose.slides-15.9.0.jar</systemPath>
</dependency>
二、工具类
这边将每个基本类型都整成一个方法了。
public class OssTypeUtlis {
public static void main(String[] args) {
//word2pdf("C:/Users/Administrator/Desktop/1.doc","C:/Users/Administrator/Desktop/xxxx.pdf");//word转pdf
//word转图片格式
try {
String path = "C:/Users/John/Desktop/1.pdf";
File file = new File(path);
InputStream inStream = new FileInputStream(file);
List<BufferedImage> wordToImg = pdfToimg(inStream);//
BufferedImage mergeImage = mergeImage(false, wordToImg);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
ImageIO.write(mergeImage, "jpg", new File("C:/Users/John/Desktop/1.jpg")); //将其保存在C:/imageSort/targetPIC/下
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @Description: 验证aspose.word组件是否授权:无授权的文件有水印标记
*/
public static boolean isWordLicense() {
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>";
boolean result = false;
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes());

该文介绍了如何使用Aspose库将不同类型的文件(如Word、Excel、PPT、PDF)转换为图片以便在安卓设备上预览,然后上传到阿里云。过程中涉及到了jar依赖、转换工具类的编写以及Linux环境下解决中文乱码问题的方法。

5502

被折叠的 条评论
为什么被折叠?



