标签:word words 记录 os new File import pdf com
只需要输出路径和输入路径即可,pom和license在另一个帖子(aspose18.6)里面
主要实现
package com.microstone.product.util;
import com.aspose.words.Document;
import com.aspose.words.FontSettings;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import org.microstone.core.tool.utils.Func;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
public class PdfUtil {
public static boolean getLicense() {
boolean result = false;
try {
//InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/license.xml");
InputStream is = PdfUtil.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml应放在…\WebRoot\WEB-INF\classes路径下
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void doc2pdf(String input,String output) {
if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
FontSettings.getDefaultInstance().setFontsFolder(File.separator + "usr" + File.separator + "share" + File.separator + "fonts" +File.separator + "zh_CN",true);
if(Func.notNull(System.getProperties().get("os.name")) && ((String) System.getProperties().get("os.name")).contains("Windows")){
FontSettings.getDefaultInstance().setFontsFolder("C:\\Windows\\Fonts",true);
}
File file = new File(output); //新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(input); //Address是将要被转化的word文档
doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
标签:word,words,记录,os,new,File,import,pdf,com 来源: https://blog.csdn.net/weixin_46697618/article/details/121682387
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。