| | |
| | | package com.zy.crm.manager.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.documents4j.api.DocumentType; |
| | | import com.documents4j.api.IConverter; |
| | | import com.documents4j.job.LocalConverter; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.apache.xmlbeans.XmlCursor; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; |
| | |
| | | import java.io.*; |
| | | import java.text.DecimalFormat; |
| | | import java.text.NumberFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | .body(resource); |
| | | } |
| | | |
| | | /* |
| | | * word转PDF |
| | | * */ |
| | | public static void documents4jWordToPdf(String sourcePath, String targetPath) { |
| | | File inputWord = new File(sourcePath); |
| | | File outputFile = new File(targetPath); |
| | | try { |
| | | InputStream docxInputStream = new FileInputStream(inputWord); |
| | | OutputStream outputStream = new FileOutputStream(outputFile); |
| | | IConverter converter = LocalConverter.builder().build(); |
| | | boolean execute = converter.convert(docxInputStream) |
| | | .as(DocumentType.DOCX) |
| | | .to(outputStream) |
| | | .as(DocumentType.PDF).schedule().get(); |
| | | outputStream.close(); |
| | | docxInputStream.close(); |
| | | |
| | | System.out.println("转换完毕 targetPath = "+outputFile.getAbsolutePath()); |
| | | converter.shutDown(); |
| | | return; |
| | | } catch (Exception e) { |
| | | System.out.println("[documents4J] word转pdf失败:"+e.toString()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理段落中文本,替换文本中定义的变量; |
| | | * @param param 需要替换的变量及变量值 |