最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java使用aspose實現(xiàn)pdf轉(zhuǎn)word

 更新時間:2025年02月08日 10:54:03   作者:Lovme_du  
Aspose是一套強大的文檔處理工具,被超過80%的財富100強公司信賴,用于在應(yīng)用程序中創(chuàng)建、編輯、導(dǎo)出和轉(zhuǎn)換100多種文件格式,本文將給大家介紹Java使用aspose實現(xiàn)pdf轉(zhuǎn)word的操作方法,需要的朋友可以參考下

Java使用aspose實現(xiàn)pdf轉(zhuǎn)word

一、下載aspose-pdf-21.6.jar包【下載地址】,存放目錄結(jié)構(gòu)如圖;配置pom.xml。

<!--pdf to word-->
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>21.6</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/lib/aspose-pdf-21.6.jar</systemPath>
</dependency>

二、創(chuàng)建PDFHelper.java類。運行代碼同目錄會出現(xiàn)docx文件。

import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import java.io.*;

public class PDFHelper3 {

    public static void main(String[] args) throws IOException {
        pdf2doc("D://test.pdf");
    }

    /**
     * pdf轉(zhuǎn)doc
     *
     * @param pdfPath pdf 路徑
     */
    public static void pdf2doc(String pdfPath) {
        try {
            //新建一個word文檔
            String wordPath = pdfPath.substring(0, pdfPath.lastIndexOf(".")) + ".docx";
            FileOutputStream os = new FileOutputStream(wordPath);
            //doc是將要被轉(zhuǎn)化的word文檔
            Document doc = new Document(pdfPath);
            //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互轉(zhuǎn)換
            doc.save(os, SaveFormat.DocX);
            os.close();
            //轉(zhuǎn)化用時
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) Word 失敗...");
            e.printStackTrace();
        }
    }
}

注意:如果aspose-pdf-21.6.jar是官網(wǎng)下載,轉(zhuǎn)換的文件有水印。需要用下面代碼運行破解,從新生成aspose-pdf-21.6.jar包引用。從我上面鏈接下載已經(jīng)破解了。

import javassist.*;

import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;

public class PDFJarCrack {


    public static void main(String[] args) throws Exception {
        String jarPath = "D:\\aspose-pdf-21.6.jar";
        crack(jarPath);
    }


    private static void crack(String jarName) {
        try {
            ClassPool.getDefault().insertClassPath(jarName);
            CtClass ctClass = ClassPool.getDefault().getCtClass("com.aspose.pdf.ADocument");
            CtMethod[] declaredMethods = ctClass.getDeclaredMethods();
            int num = 0;
            for (int i = 0; i < declaredMethods.length; i++) {
                if (num == 2) {
                    break;
                }
                CtMethod method = declaredMethods[i];
                CtClass[] ps = method.getParameterTypes();
                if (ps.length == 2
                        && method.getName().equals("lI")
                        && ps[0].getName().equals("com.aspose.pdf.ADocument")
                        && ps[1].getName().equals("int")) {
                    // 最多只能轉(zhuǎn)換4頁 處理
                    System.out.println(method.getReturnType());
                    System.out.println(ps[1].getName());
                    method.setBody("{return false;}");
                    num = 1;
                }
                if (ps.length == 0 && method.getName().equals("lt")) {
                    // 水印處理
                    method.setBody("{return true;}");
                    num = 2;
                }
            }
            File file = new File(jarName);
            ctClass.writeFile(file.getParent());
            disposeJar(jarName, file.getParent() + "/com/aspose/pdf/ADocument.class");
        } catch (NotFoundException e) {
            e.printStackTrace();
        } catch (CannotCompileException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static void disposeJar(String jarName, String replaceFile) {
        List<String> deletes = new ArrayList<>();
        deletes.add("META-INF/37E3C32D.SF");
        deletes.add("META-INF/37E3C32D.RSA");
        File oriFile = new File(jarName);
        if (!oriFile.exists()) {
            System.out.println("######Not Find File:" + jarName);
            return;
        }
        //將文件名命名成備份文件
        String bakJarName = jarName.substring(0, jarName.length() - 3) + "cracked.jar";
        //   File bakFile=new File(bakJarName);
        try {
            //創(chuàng)建文件(根據(jù)備份文件并刪除部分)
            JarFile jarFile = new JarFile(jarName);
            JarOutputStream jos = new JarOutputStream(new FileOutputStream(bakJarName));
            Enumeration entries = jarFile.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = (JarEntry) entries.nextElement();
                if (!deletes.contains(entry.getName())) {
                    if (entry.getName().equals("com/aspose/pdf/ADocument.class")) {
                        JarEntry jarEntry = new JarEntry(entry.getName());
                        jos.putNextEntry(jarEntry);
                        FileInputStream fin = new FileInputStream(replaceFile);
                        byte[] bytes = readStream(fin);
                        jos.write(bytes, 0, bytes.length);
                    } else {
                        jos.putNextEntry(entry);
                        byte[] bytes = readStream(jarFile.getInputStream(entry));
                        jos.write(bytes, 0, bytes.length);
                    }
                } else {
                    System.out.println("Delete:-------" + entry.getName());
                }
            }
            jos.flush();
            jos.close();
            jarFile.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static byte[] readStream(InputStream inStream) throws Exception {
        ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len = -1;
        while ((len = inStream.read(buffer)) != -1) {
            outSteam.write(buffer, 0, len);
        }
        outSteam.close();
        inStream.close();
        return outSteam.toByteArray();
    }
}

到此這篇關(guān)于Java使用aspose實現(xiàn)pdf轉(zhuǎn)word的文章就介紹到這了,更多相關(guān)Java aspose實現(xiàn)pdf轉(zhuǎn)word內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java中finalize()詳解及用法

    Java中finalize()詳解及用法

    這篇文章主要介紹了Java中finalize()詳解及用法的相關(guān)資料,final是Java的關(guān)鍵字,它所表示的是“這部分是無法修改的”,需要的朋友可以參考下
    2017-03-03
  • Java開發(fā)如何把數(shù)據(jù)庫里的未付款訂單改成已付款

    Java開發(fā)如何把數(shù)據(jù)庫里的未付款訂單改成已付款

    這篇文章主要介紹了Java開發(fā)如何把數(shù)據(jù)庫里的未付款訂單改成已付款,先介紹MD5算法,簡單的來說,MD5能把任意大小、長度的數(shù)據(jù)轉(zhuǎn)換成固定長度的一串字符,實現(xiàn)思路非常簡單需要的朋友可以參考下
    2022-11-11
  • Spring整合MyBatis(Maven+MySQL)圖文教程詳解

    Spring整合MyBatis(Maven+MySQL)圖文教程詳解

    這篇文章主要介紹了Spring整合MyBatis(Maven+MySQL)圖文教程詳解的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • java教程之java繼承示例詳解

    java教程之java繼承示例詳解

    這篇文章主要介紹了java繼承示例詳解,需要的朋友可以參考下
    2014-04-04
  • Java Scanner對象中hasNext()與next()方法的使用

    Java Scanner對象中hasNext()與next()方法的使用

    這篇文章主要介紹了Java Scanner對象中hasNext()與next()方法的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Spring Boot使用Druid連接池的示例代碼

    Spring Boot使用Druid連接池的示例代碼

    Druid是Java語言中最好的數(shù)據(jù)庫連接池。這篇文章主要介紹了Spring Boot使用Druid連接池的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • Java中判斷集合是否相等的幾種方法詳解

    Java中判斷集合是否相等的幾種方法詳解

    這篇文章主要介紹了Java中判斷集合是否相等的幾種方法詳解,在平時的開發(fā)中,可能會遇到需要判斷兩個集合是否相等的需求,那么本文就來詳細(xì)講解一下幾種實現(xiàn)方法,需要的朋友可以參考下
    2023-08-08
  • Spring Boot 日志功能深度解析與實踐指南

    Spring Boot 日志功能深度解析與實踐指南

    本文詳細(xì)介紹了SpringBoot的日志功能,包括默認(rèn)日志框架Logback,日志級別配置,日志格式自定義,日志文件輸出,日志歸檔與清理,自定義日志配置,與其他日志框架的集成以及日志性能優(yōu)化,通過結(jié)合實際場景,提供了詳細(xì)的配置與實踐指南,感興趣的朋友一起看看吧
    2025-01-01
  • Java編程線程同步工具Exchanger的使用實例解析

    Java編程線程同步工具Exchanger的使用實例解析

    這篇文章主要介紹了Java編程線程同步工具Exchanger的使用實例解析,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • Spring服務(wù)注解有哪些

    Spring服務(wù)注解有哪些

    這篇文章主要介紹了Spring服務(wù)注解,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2016-11-11

最新評論

峨边| 潍坊市| 依兰县| 兰西县| 乌拉特后旗| 苏州市| 阿图什市| 璧山县| 金溪县| 绥阳县| 武城县| 新民市| 永川市| 时尚| 阿坝县| 江孜县| 泰和县| 思茅市| 双流县| 屏山县| 惠来县| 育儿| 安溪县| 土默特右旗| 宜都市| 山东省| 阿拉善盟| 乐亭县| 洛扎县| 孝感市| 平陆县| 修文县| 莆田市| 天柱县| 陇川县| 阿城市| 延津县| 平乡县| 穆棱市| 攀枝花市| 靖州|