package cn.report.test.ok;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.jodconverter.core.office.OfficeException;
import org.jodconverter.core.office.OfficeManager;
import org.jodconverter.local.JodConverter;
import org.jodconverter.local.office.LocalOfficeManager;

import cn.report.excel.easyexcel.api.EasyExcel;
import cn.report.excel.easyexcel.api.EasyExcelFactory;
import cn.report.excel.easyexcel.api.ExcelWriter;
import cn.report.excel.easyexcel.api.write.metadata.WriteSheet;
import cn.report.test.DemoData;

public class Test {

	/**
	 * 将word模板转化成pdf
	 * @param args
	 * @throws Exception
	 */
	
	public static void main(String[] args) throws Exception {
		String templatePath = "D:\\data\\bjtu\\template\\certificate.docx";
		String out4 = "F:\\temp\\template.pdf";
		//Word2Pdf(templatePath, out);
		      
 
       
	}
	
		
	///////////////////////////
	public static void Word2Pdf(String srcPath, String desPath) throws IOException {
	    // 源文件目录
	    File inputFile = new File(srcPath);
	    if (!inputFile.exists()) {
	        System.out.println("源文件不存在！");
	        return;
	    }
	    // 输出文件目录
	    File outputFile = new File(desPath);
	    if (!outputFile.getParentFile().exists()) {
	        outputFile.getParentFile().exists();
	    }
	    
	    // 连接OpenOffice/LibreOffice服务
	    OfficeManager officeManager = LocalOfficeManager
	    		.builder()
	    		.officeHome("D:\\program\\LibreOffice")
	    		.install().build();
	    try {
	    	//启动OpenOffice服务
	        officeManager.start();
	        // 转换文档到pdf
	         JodConverter.convert(inputFile).to(outputFile).execute();
	        
	    } catch (Exception e) {
	        e.printStackTrace();
	        
	    } finally {
	    	//停止服务
	        try {
				officeManager.stop();
			} catch (OfficeException e) {
				
			}
	    }
	}
	
}
