word, excel pdf로 변환

OpenOffice를 사용해야 하므로 먼저 OpenOffice를 설치해야 합니다.
그리고 자바 코드:
package com.lynxiaojing.officereview;
import java.io.File;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
public class TTTTTT {
    public static void main(String[] args) {
                      
        // 1) Start LibreOffice in headless mode.
        OfficeManager officeManager = null;
        try {
            officeManager = new DefaultOfficeManagerConfiguration()
                    .setOfficeHome(new File("D:\\Program Files (x86)\\OpenOffice 4"))//openOffice 
                    .buildOfficeManager();
            officeManager.start();
              
            // 2) Create JODConverter converter
            OfficeDocumentConverter converter = new OfficeDocumentConverter(
                    officeManager);
              
            // 3) Create PDF
//            createPDF(converter);
            createPDF(converter);
              
        } finally {
            // 4) Stop LibreOffice in headless mode.
            if (officeManager != null) {
                officeManager.stop();
            }
        }
    }
              
    private static void createPDF(OfficeDocumentConverter converter) {
        try {
            long start = System.currentTimeMillis();
            converter.convert(new File("d:/WP8 --NavigationService .docx"), new File(
                    "d:/HelloWorld.pdf"));
            System.out.println("Generate pdf/HelloWorld.pdf with "
                    + (System.currentTimeMillis() - start) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}

jar 패키지 주소:http://download.csdn.net/detail/water_lang/6926897

좋은 웹페이지 즐겨찾기