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

Java實(shí)現(xiàn)PDF轉(zhuǎn)HTML/Word/Excel/PPT/PNG的示例代碼

 更新時(shí)間:2022年05月31日 15:10:38   作者:洛陽(yáng)泰山  
這篇文章主要為大家介紹了如何利用Java語言是PDF轉(zhuǎn)HTML、Word、Excel、PPT和PNG功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下

從 Maven 下載 Aspose.PDF

通過將以下配置添加到 pom.xml, 您可以直接從基于Maven的項(xiàng)目 輕松地使用Aspose.PDF for Java 。

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>22.4</version>
</dependency>

核心代碼實(shí)現(xiàn)(單類)

 
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import com.aspose.pdf.devices.PngDevice;
import com.aspose.pdf.devices.Resolution;
 
import java.io.*;
 
public class PDFHelper3 {
 
    public static void main(String[] args) throws IOException {
        pdf2image("C:\\Users\\liuya\\Desktop\\pdf\\示例文件.pdf");
    }
 
 
    //轉(zhuǎn)word
    public static void pdf2word(String pdfPath) {
        long old = System.currentTimeMillis();
        try {
            String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".docx";
            FileOutputStream os = new FileOutputStream(wordPath);
            Document doc = new Document(pdfPath);
            doc.save(os, SaveFormat.DocX);
            os.close();
            long now = System.currentTimeMillis();
            System.out.println("Pdf 轉(zhuǎn) Word 共耗時(shí):" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) Word 失敗...");
            e.printStackTrace();
        }
    }
 
    //轉(zhuǎn)ppt
    public static void pdf2ppt(String pdfPath) {
        long old = System.currentTimeMillis();
        try {
            String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".ppt";
            FileOutputStream os = new FileOutputStream(wordPath);
            Document doc = new Document(pdfPath);
            doc.save(os, SaveFormat.Pptx);
            os.close();
            long now = System.currentTimeMillis();
            System.out.println("Pdf 轉(zhuǎn) PPT 共耗時(shí):" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) PPT 失敗...");
            e.printStackTrace();
        }
    }
 
    //轉(zhuǎn)excel
    public static void pdf2excel(String pdfPath) {
        long old = System.currentTimeMillis();
        try {
            String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".xlsx";
            FileOutputStream os = new FileOutputStream(wordPath);
            Document doc = new Document(pdfPath);
            doc.save(os, SaveFormat.Excel);
            os.close();
            long now = System.currentTimeMillis();
            System.out.println("Pdf 轉(zhuǎn) EXCEL 共耗時(shí):" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) EXCEL 失敗...");
            e.printStackTrace();
        }
    }
 
    //轉(zhuǎn)html
    public static void pdf2Html(String pdfPath) {
        long old = System.currentTimeMillis();
        try {
            String htmlPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".html";
            Document doc = new Document(pdfPath);
            doc.save(htmlPath,SaveFormat.Html);
            long now = System.currentTimeMillis();
            System.out.println("Pdf 轉(zhuǎn) HTML 共耗時(shí):" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) HTML 失敗...");
            e.printStackTrace();
        }
    }
 
    //轉(zhuǎn)圖片
    public static void pdf2image(String pdfPath) {
        long old = System.currentTimeMillis();
        try {
            Resolution resolution = new Resolution(300);
            String dataDir=pdfPath.substring(0,pdfPath.lastIndexOf("."));
            File imageDir = new File(dataDir+"_images");
            imageDir.mkdirs();
            Document doc = new Document(pdfPath);
            PngDevice pngDevice = new PngDevice(resolution);
            for (int pageCount = 1; pageCount <= doc.getPages().size(); pageCount++) {
                OutputStream imageStream = new FileOutputStream(imageDir+"/"+pageCount+".png");
                pngDevice.process(doc.getPages().get_Item(pageCount), imageStream);
                imageStream.close();
            }
            long now = System.currentTimeMillis();
            System.out.println("Pdf 轉(zhuǎn) PNG 共耗時(shí):" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            System.out.println("Pdf 轉(zhuǎn) PNG 失敗...");
            e.printStackTrace();
        }
    }
 
 
}

運(yùn)行方法,idea里右鍵運(yùn)行,如果要做成web系統(tǒng)可以將代碼封裝程web服務(wù),調(diào)用方法就行。

轉(zhuǎn)換文件結(jié)果

以一個(gè)十四的pdf文件轉(zhuǎn)化為例,大部分轉(zhuǎn)換時(shí)間在10-12s,只有轉(zhuǎn)ppt花費(fèi)的時(shí)間久一點(diǎn)需要20s.可能pdf里面不是表格類的內(nèi)容,所以轉(zhuǎn)換excel文件后,樣式差別會(huì)有點(diǎn)大,其他文件轉(zhuǎn)換后樣式和之前是保持一樣的。

以上就是Java實(shí)現(xiàn)PDF轉(zhuǎn)HTML/Word/Excel/PPT/PNG的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于Java PDF轉(zhuǎn)HTML Word Excel PPT PNG的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Springcloud Bus消息總線原理是實(shí)現(xiàn)詳解

    Springcloud Bus消息總線原理是實(shí)現(xiàn)詳解

    Spring Cloud Bus 使用輕量級(jí)的消息代理來連接微服務(wù)架構(gòu)中的各個(gè)服務(wù),可以將其用于廣播狀態(tài)更改(例如配置中心配置更改)或其他管理指令,本文將對(duì)其用法進(jìn)行詳細(xì)介紹
    2022-09-09
  • Java實(shí)現(xiàn)PDF轉(zhuǎn)HTML/Word/Excel/PPT/PNG的示例代碼

    Java實(shí)現(xiàn)PDF轉(zhuǎn)HTML/Word/Excel/PPT/PNG的示例代碼

    這篇文章主要為大家介紹了如何利用Java語言是PDF轉(zhuǎn)HTML、Word、Excel、PPT和PNG功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2022-05-05
  • jvm內(nèi)存溢出解決方法(jvm內(nèi)存溢出怎么解決)

    jvm內(nèi)存溢出解決方法(jvm內(nèi)存溢出怎么解決)

    jvm內(nèi)存溢出解決方法,詳細(xì)內(nèi)容看下面解釋
    2013-12-12
  • 數(shù)組重排序(如何將所有奇數(shù)都放在所有偶數(shù)前面)的深入分析

    數(shù)組重排序(如何將所有奇數(shù)都放在所有偶數(shù)前面)的深入分析

    本篇文章是對(duì)數(shù)組重排序(如何將所有奇數(shù)都放在所有偶數(shù)前面)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • 解析Mybatis Porxy動(dòng)態(tài)代理和sql解析替換問題

    解析Mybatis Porxy動(dòng)態(tài)代理和sql解析替換問題

    這篇文章主要介紹了Mybatis Porxy動(dòng)態(tài)代理和sql解析替換,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • Maven 的配置文件路徑讀取方法

    Maven 的配置文件路徑讀取方法

    這篇文章主要介紹了Maven 的配置文件路徑讀取方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • Java集合WeakHashMap源碼分析

    Java集合WeakHashMap源碼分析

    這篇文章主要介紹了Java集合WeakHashMap源碼分析,和HashMap一樣,WeakHashMap 也是一個(gè)散列表,它存儲(chǔ)的內(nèi)容也是鍵值對(duì)(key-value)映射,而且鍵和值都可以是null,需要的朋友可以參考下
    2023-09-09
  • http調(diào)用controller方法時(shí)openfeign執(zhí)行流程

    http調(diào)用controller方法時(shí)openfeign執(zhí)行流程

    這篇文章主要為大家介紹了http調(diào)用controller方法時(shí)openfeign執(zhí)行流程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • 一文精通Java中的volatile關(guān)鍵字

    一文精通Java中的volatile關(guān)鍵字

    volatile是java中的關(guān)鍵詞之一,這篇文章主要給大家介紹了關(guān)于Java中volatile關(guān)鍵字的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • Java秒殺系統(tǒng):web層詳解

    Java秒殺系統(tǒng):web層詳解

    本文主要介紹了如何設(shè)計(jì)一個(gè)秒殺系統(tǒng)的web層相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧,希望能夠給你帶來幫助
    2021-10-10

最新評(píng)論