word的xml格式转为普通的doc或者docx格式怎么转,请大神指教!!
使用java将freemarker根据ftl模板生成的word文件转化为PDF
freemarker转成的word是xml格式,转成PDF时显示的是xml内容
将freemarker生成的文件另存成doc文件,再使用openoffice转化可以正常转化
请大神指教,怎么可以将freemarker生成的word文件转为PDF文件

freemarker转成的word是xml格式,转成PDF时显示的是xml内容
将freemarker生成的文件另存成doc文件,再使用openoffice转化可以正常转化
请大神指教,怎么可以将freemarker生成的word文件转为PDF文件
//freemarker生成word文件
public static void printToPdf(String templatePath, String templateName, Map<String, Object> dataMap,
String tmpUrl) {
configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
configuration.setServletContextForTemplateLoading(ServletContextUtils.getServletContext(), templatePath);
Template t = null;
try {
t = configuration.getTemplate(templateName);
File outFile = new File(tmpUrl);
Writer out = null;
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
t.process(dataMap, out);
IOUtils.closeQuietly(out);
String source = tmpUrl;
String target = tmpUrl.substring(0, tmpUrl.lastIndexOf('.')) + ".pdf";
word2pdf(source, target);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
}//转PDF
private static void word2pdf(String source, String target) {
String OpenOffice_HOME = "G:/soft/openoffice/";//openoffice安装目录
if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '/') {
OpenOffice_HOME += "/";
}
Process pro = null;
try {
File inputFile = new File(source);
File outputFile = new File(target);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
String command = OpenOffice_HOME
+ "program\\soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;StarOffice.ServiceManager\" -nofirststartwizard";
pro = Runtime.getRuntime().exec(command);
OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
connection.disconnect();
pro.destroy();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
pro.destroy();
}
}
...全文
相关推荐
word文件批量替换(word转xml、xml转字符串、doc转docx)
涉及知识点:word转xml、xml转字符串、doc转docx 此处主要试讲word文件转换,之前的替换只能替换正文,此处可进行全部替换,像脚注等,都可进行
Java POI实现Word转HTML:支持.doc与.docx格式的完整解决方案
Apache POI是Java生态中处理Microsoft Office文档的标准开源库,广泛应用于报表生成、数据导入导出等场景。其核心模块HWPF(Horrible Word Processor Format)用于读写传统的.doc二进制文件,基于OLE复合文档结构解析文本与格式;而XWPF(XML-based Word Processor Format)则面向.docx格式,依托Office Open XML标准,通过ZIP封装内的XML文件实现内容抽取。关键类如和分别代表文档整体模型,
Word(docx/doc)批量转txt工具
docx批量转txt
java读取doc、docx文件,java pdf转word
zip文件解压,直接导入到eclipse里 有两个类 分别支持读取word和pdf转word,pdf转word样式百分百保留,license证书已pj,如需商业用途请购买正版证书
docx2doc docx转doc
提供docx格式的word文档转换为doc格式的word文档简介demo


Web 开发
