PDF完美转换word

1.首先下载 ASPOSE - WORD jar包放在lib下
PDF完美转换word_第1张图片
image.png
2.添加 license.xml文件

  
    
      Aspose.Total for Java
      Aspose.Pdf for Java
    
    Enterprise
    20991231
    20991231
    8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7
  
  sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=

3.示例代码
package com.duor.aladdin.report.util;

import com.aspose.pdf.License;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;

import java.io.*;

public class AsposeWordsUtils {
    private static InputStream license;
    private static InputStream fileInput;
    private static File outputFile;

/**
     * 获取license
     *
     * @return
     */

    public static boolean getLicense() {
        boolean result = false;
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            license = new FileInputStream(loader.getResource("exportXml/license.xml").getPath());// 凭证文件
            fileInput = new FileInputStream(loader.getResource("pdf/Report.pdf").getPath());// 待处理的文件
            outputFile = new File("D:\\company\\develop\\aladdin2\\aladdin_report\\src\\main\\resources\\123.doc");// 输出路径

            License aposeLic = new License();
            aposeLic.setLicense(license);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

/**
     *
     * @param args
     */

    public static void main(String[] args) {
        // 验证License
        if (!getLicense()) {
            return;
        }

        try {
            long old = System.currentTimeMillis();
            Document pdfDocument = new Document(fileInput);
            OutputStream fileOutput = new FileOutputStream(outputFile);

            pdfDocument.save(fileOutput, SaveFormat.DocX);

            long now = System.currentTimeMillis();
            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒\n\n" + "文件保存在:" + outputFile.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

即可完美转换

你可能感兴趣的:(PDF完美转换word)