java aspose.cells excel转pdf
添加aspose依赖
aspose.cells依赖下载下来,本地导入进pom,尽量放在项目文件夹里
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose</artifactId>
<version>8.5.2</version>
<scope>system</scope
<systemPath>${pom.basedir}/src/main/resources/templates/aspose-cells-20.7-crack.jar</systemPath>
</dependency>
excel转pdf代码
package com.zhenghe.api.manager.service.exportData;
import com.aspose.cells.*;
import org.springframework.stereotype.Service;
import java.io.*;
@Service
public class PdfService {
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = PdfService.class.getClassLoader().getResourceAsStream("templates/license.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* excel 转为pdf 输出。
*
* @param sourceFilePath excel文件
* @param desFilePathd pad 输出文件目录
*/
public static void excel2pdf(String sourceFilePath, String desFilePathd ){
if (!getLicense()) { // 验证License 不然会有水印
return;
}
try {
//aspose必须要20以上的版本不然会报错,说没有IndividualFontConfigs这个类
//设置字体,如果不把本地的字体上传到服务的话。出来的pdf会乱码,
IndividualFontConfigs configs = new IndividualFontConfigs();
configs.setFontFolder("/usr/share/fonts/chinese", true);
LoadOptions loadOptions = new LoadOptions();
loadOptions.setFontConfigs(configs);
Workbook wb = new Workbook(sourceFilePath,loadOptions);// 原始excel路径
FileOutputStream fileOS = new FileOutputStream(desFilePathd);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
int[] autoDrawSheets={3};
int[] showSheets={0};
printSheetPage(wb,showSheets);
wb.save(fileOS, pdfSaveOptions);
fileOS.flush();
fileOS.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void printSheetPage(Workbook wb,int[] page){
for (int i= 1; i < wb.getWorksheets().getCount(); i++) {
wb.getWorksheets().get(i).setVisible(false);
}
if(null==page||page.length==0){
wb.getWorksheets().get(0).setVisible(true);
}else{
for (int i = 0; i < page.length; i++) {
wb.getWorksheets().get(i).setVisible(true);
}
}
}
}
aspose破解xml
<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>
##例外
如果打包到服务器上报错运行不起来
请按以下操作
图片:
然后正在进行打包,说不定就可以了,我也是稀里糊涂的就可以了
可能是我重启过电脑,在打包的