亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

Java使用aspose實(shí)現(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類。運(yùn)行代碼同目錄會(huì)出現(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 {
            //新建一個(gè)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)化用時(shí)
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) Word 失敗...");
            e.printStackTrace();
        }
    }
}

注意:如果aspose-pdf-21.6.jar是官網(wǎng)下載,轉(zhuǎn)換的文件有水印。需要用下面代碼運(yù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實(shí)現(xiàn)pdf轉(zhuǎn)word的文章就介紹到這了,更多相關(guān)Java aspose實(shí)現(xiàn)pdf轉(zhuǎn)word內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • MyBatis-Plus?分頁不生效的解決方法

    MyBatis-Plus?分頁不生效的解決方法

    本文主要介紹了MyBatis-Plus?分頁不生效的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • Java中字符串String的+和+=及循環(huán)操作String原理詳解

    Java中字符串String的+和+=及循環(huán)操作String原理詳解

    Java編譯器在編譯時(shí)對String的+和+=操作會(huì)創(chuàng)建StringBuilder對象來進(jìn)行字符串的拼接,下面這篇文章主要給大家介紹了關(guān)于Java中字符串String的+和+=及循環(huán)操作String原理的相關(guān)資料,需要的朋友可以參考下
    2023-01-01
  • Java文件拒絕訪問問題及解決

    Java文件拒絕訪問問題及解決

    這篇文章主要介紹了Java文件拒絕訪問問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Spring中@Configuration注解的使用場景

    Spring中@Configuration注解的使用場景

    這篇文章主要介紹了Spring中@Configuration注解的使用場景,@Configuration注解是從Spring?3.0版本開始加入的一個(gè)使Spring能夠支持注解驅(qū)動(dòng)開發(fā)的標(biāo)注型注解,主要用于標(biāo)注在類上,需要的朋友可以參考下
    2023-11-11
  • 詳解SimpleDateFormat的線程安全問題與解決方案

    詳解SimpleDateFormat的線程安全問題與解決方案

    這篇文章主要介紹了SimpleDateFormat的線程安全問題與解決方案,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-03-03
  • Mybatis 傳參與排序模糊查詢功能實(shí)現(xiàn)

    Mybatis 傳參與排序模糊查詢功能實(shí)現(xiàn)

    這篇文章主要介紹了Mybatis 傳參與排序模糊查詢功能實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2025-04-04
  • javaWEB中前后臺(tái)亂碼問題的解決方法總結(jié)

    javaWEB中前后臺(tái)亂碼問題的解決方法總結(jié)

    下面小編就為大家?guī)硪黄猨avaWEB中前后臺(tái)亂碼問題的解決方法總結(jié)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • Java線程的停止實(shí)現(xiàn)原理詳解

    Java線程的停止實(shí)現(xiàn)原理詳解

    這篇文章主要介紹了Java線程的停止實(shí)現(xiàn)原理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-01-01
  • spring單元測試下模擬rabbitmq的實(shí)現(xiàn)

    spring單元測試下模擬rabbitmq的實(shí)現(xiàn)

    這篇文章主要介紹了spring單元測試下模擬rabbitmq的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • JAVA使用HtmlUnit爬蟲工具模擬登陸CSDN案例

    JAVA使用HtmlUnit爬蟲工具模擬登陸CSDN案例

    今天小編就為大家分享一篇關(guān)于JAVA使用HtmlUnit爬蟲工具模擬登陸CSDN案例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12

最新評論