java 实现pdf.js加aspose实现doc转pdf
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java 实现pdf.js加aspose实现doc转pdf,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2426字,纯文字阅读大概需要4分钟。
内容图文
![java 实现pdf.js加aspose实现doc转pdf](/upload/InfoBanner/zyjiaocheng/765/d368977911e648b989ab1485a5a494c9.jpg)
package com.bangzheng.common.bzcommon;
import com.aspose.words.Document;
import com.aspose.words.FontSettings;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.jfinal.kit.PathKit;
import org.apache.logging.log4j.core.config.plugins.util.ResolverUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
/**
-
@author Administrator
*/
public class Doc2Pdf {/**
- 日志
*/
private static final Logger logger = LoggerFactory.getLogger(Doc2Pdf.class);
/public static void main(String[] args) {
Doc2Pdf.doc2pdf(“D:/国家总体应急预案.docx”, “F:/XYpxyl/”, “asd”);
}/
public static boolean getLicense() {
boolean result = false;
try {
// license.xml应放在…\WebRoot\WEB-INF\classes路径下
InputStream is = ResolverUtil.Test.class.getClassLoader().getResourceAsStream(“license.xml”);
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}/**
- word转pdf
- @param inPath
- @param outPath
- @param fileName
- @return
/
public static String doc2pdf(String inPath, String outPath, String fileName) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getLicense()) {
return null;
}
try {
long old = System.currentTimeMillis();
//上传地址路径
String uploadPath = PathKit.getWebRootPath() + File.separator + outPath;
File file = new File(uploadPath + File.separator + fileName.substring(0, fileName.lastIndexOf(".")) + “.pdf”);
FileOutputStream os = new FileOutputStream(file);
//设置一个字体目录
/ FontSettings.setFontsFolder("/fonts/chinese/consola.ttf", false);/
//设置多个字体目录
/ String[] fonts = {"/fonts/chinese/consola.ttf", “/fonts/chinese/simsun.ttf”, “/fonts/chinese/msyh.ttf”, “/fonts/chinese/msyhbd.ttf”, “/fonts/chinese/simfang.ttf”, “/fonts/chinese/simhei.ttf”, “/fonts/chinese/simkai.ttf”, “/fonts/chinese/simsunb.ttf”};
FontSettings.setFontsFolders(fonts, true);*/
//Address是将要被转化的word文档
Document doc = new Document(inPath);
//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
doc.save(os, SaveFormat.PDF);
os.close();
long now = System.currentTimeMillis();
//转化用时
logger.info(fileName + “转pdf共耗时:” + ((now - old) / 1000.0) + “秒”);
os.close();
return outPath + File.separator + file.getName();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
- 日志
}
内容总结
以上是互联网集市为您收集整理的java 实现pdf.js加aspose实现doc转pdf全部内容,希望文章能够帮你解决java 实现pdf.js加aspose实现doc转pdf所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。