广告
返回顶部
首页 > 资讯 > 移动开发 >Android实现excel/pdf/word/odt/图片相互转换
  • 603
分享到

Android实现excel/pdf/word/odt/图片相互转换

摘要

目录实践过程pdf转excelexcel转pdfppt转pdfpdf转pptpdf转Wordword转pdfexcel转图片pdf转图片odt转pdf实践过程 pdf转excel p

实践过程

pdf转excel

public static long pdfToExcel(String inFile, String outFile) throws Exception {
    if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        Document doc = new Document(inFile);
        ExcelSaveOptions options = new ExcelSaveOptions();
        options.setFORMat(ExcelSaveOptions.ExcelFormat.XLSX);
        doc.save(outFile, options);
        Out.print(inFile, outFile, System.currentTimeMillis(), old);
        return new File(outFile).length();
    }catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

excel转pdf

public static long excelToPdf(String inFile, String outFile) throws Exception {
    if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        File pdfFile = new File(outFile);
        Workbook wb = new Workbook(inFile);
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setOnePagePerSheet(true);
        FileOutputStream fileOS = new FileOutputStream(pdfFile);
        wb.save(fileOS, SaveFormat.PDF);
        fileOS.close();
        long now = System.currentTimeMillis();
        Out.print(inFile, outFile, now, old);
        return pdfFile.length();
    }catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

ppt转pdf

public static long pptToPdf(String inFile, String outFile) throws Exception {
 if (!com.yrnet.transfer.business.transfer.file.License.getPptLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        File pdfFile = new File(outFile);
        FileOutputStream os = new FileOutputStream(pdfFile);
        Presentation pres = new Presentation(inFile);
        pres.save(os, com.aspose.slides.SaveFormat.Pdf);
        os.close();
        long now = System.currentTimeMillis();
        Out.print(inFile, outFile, now, old);
        return pdfFile.length();
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

pdf转ppt

public static long pdfToPpt(String inFile, String outFile) {
   if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return 0;
    }
    long old = System.currentTimeMillis();
    Document pdfDocument = new Document(inFile);
    PptxSaveOptions pptxOptions = new PptxSaveOptions();
    pptxOptions.setExtractOcrSublayerOnly(true);
    pdfDocument.save(outFile, pptxOptions);
    long now = System.currentTimeMillis();
    Out.print(inFile, outFile, now, old);
    return new File(outFile).length();
}

pdf转word

public static long pdfToDoc(String inFile, String outFile) {
  if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return 0;
    }
    log.info("开始转换...");
    long old = System.currentTimeMillis();
    Document pdfDocument = new Document(inFile);
    DocSaveOptions saveOptions = new DocSaveOptions();
    
    saveOptions.setFormat(DocSaveOptions.DocFormat.Doc);
    pdfDocument.save(outFile, saveOptions);
    long now = System.currentTimeMillis();
    Out.print(inFile, outFile, now, old);
    log.info("转换结束...");
    return new File(outFile).length();
}

word转pdf

public static long wordToPdf(String inFile, String outFile) throws Exception {
    if (!com.yrnet.transfer.business.transfer.file.License.getWordLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        File file = new File(outFile);
        FileOutputStream os = new FileOutputStream(file);
        Document doc = new Document(inFile);
        Document tmp = new Document();
        tmp.removeAllChildren();
        tmp.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
        System.out.println("开始解析word文档" + inFile);
        doc.save(os, SaveFormat.PDF);
        long now = System.currentTimeMillis();
        log.info("target file size:{}",file.length());
        os.close();
        Out.print(inFile, outFile, now, old);
        return file.length();
    } catch (Exception e) {
        log.error(inFile + "转换失败,请重试",e);
        throw new Exception(e.getMessage());
    }
}

excel转图片

public static long excelToPic(String inFile, String outFile) throws Exception {
   if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        Workbook wb = new Workbook(inFile);
        Worksheet sheet = wb.getWorksheets().get(0);
        ImageOrPrintOptions imGoptions = new ImageOrPrintOptions();
        imgOptions.setImageFormat(ImageFormat.getPng());
        imgOptions.setCellAutoFit(true);
        imgOptions.setOnePagePerSheet(true);
        SheetRender render = new SheetRender(sheet, imgOptions);
        render.toImage(0, outFile);
        long now = System.currentTimeMillis();
        Out.print(inFile, outFile, now, old);
        return new File(outFile).length();
    }catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

pdf转图片

public static long pdfToPng(String inFile, List<String> outFile) throws Exception {
  long size = 0;
   if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
       return size;
   }
   try {
       long old = System.currentTimeMillis();
       Document pdfDocument = new Document(inFile);
       Resolution resolution = new Resolution(960);
       JpegDevice jpegDevice = new JpegDevice(resolution);
       for (int index=1;index<=pdfDocument.getPages().size();index++) {
           String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png";
           File file = new File(path);
           size += file.length();
           FileOutputStream fileOs = new FileOutputStream(file);
           jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs);
           outFile.add(path);
           fileOs.close();
           long now = System.currentTimeMillis();
           Out.print(inFile, path, now, old);
       }
       return size;
   }catch (Exception e){
       log.error(e.getMessage(),e);
       throw new Exception(e.getMessage());
   }
}

odt转pdf

public static long pdfToPng(String inFile, List<String> outFile) throws Exception {
  long size = 0;
    if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return size;
    }
    try {
        long old = System.currentTimeMillis();
        Document pdfDocument = new Document(inFile);
        Resolution resolution = new Resolution(960);
        JpegDevice jpegDevice = new JpegDevice(resolution);
        for (int index=1;index<=pdfDocument.getPages().size();index++) {
            String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png";
            File file = new File(path);
            size += file.length();
            FileOutputStream fileOs = new FileOutputStream(file);
            jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs);
            outFile.add(path);
            fileOs.close();
            long now = System.currentTimeMillis();
            Out.print(inFile, path, now, old);
        }
        return size;
    }catch (Exception e){
        log.error(e.getMessage(),e);
        throw new Exception(e.getMessage());
    }
}

以上就是Android实现excel/pdf/word/odt/图片相互转换的详细内容,更多关于Android excel pdf word odt图片转换的资料请关注编程网其它相关文章!

--结束END--

本文标题: Android实现excel/pdf/word/odt/图片相互转换

本文链接: https://www.lsjlt.com/news/209288.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android实现excel/pdf/word/odt/图片相互转换
    目录实践过程pdf转excelexcel转pdfppt转pdfpdf转pptpdf转wordword转pdfexcel转图片pdf转图片odt转pdf实践过程 pdf转excel p...
    99+
    2023-05-15
    Android excel pdf word odt图片转换 Android excel pdf word odt 图片 Android excel Android pdf Android word
  • Android怎么实现excel/pdf/word/odt/图片相互转换
    本篇内容主要讲解“Android怎么实现excel/pdf/word/odt/图片相互转换”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android怎么实现excel/pdf/word/odt...
    99+
    2023-07-06
  • C#实现Word和ODT文档相互转换详解
    目录程序环境方法1方法2格式转换1. Word转为ODTC#vb.net2. ODT转为WordC#vb.netODT文档格式一种开放文档格式(OpenDocument Text)。...
    99+
    2022-11-13
  • C#怎么实现Word和ODT文档相互转换
    本篇内容介绍了“C#怎么实现Word和ODT文档相互转换”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!ODT文档格式一种开放文档格式(Ope...
    99+
    2023-06-30
  • Python 图片与pdf相互转换
    使用到第三方库 PyMuPDF 在 python 环境下对 PDF 文件的操作。 PDF 转为图片 需新建文件夹 pdf2png import fitz import glob def rightinput(desc): ...
    99+
    2023-01-31
    图片 Python pdf
  • PythonPyMuPDF实现PDF与图片和PPT相互转换
    目录安装与简介MuPDFPyMuPDFPyMuPDF使用元数据页面Page代码示例PDF转图片图片转PDFPDF转PPT文章目录 安装与简介MuPDFPyMuPDF PyMuPDF使...
    99+
    2022-12-23
    Python PyMuPDF Python PDF转图片 Python PDF转PPT
  • Python PyMuPDF如何实现PDF与图片和PPT相互转换
    这篇文章主要介绍了Python PyMuPDF如何实现PDF与图片和PPT相互转换的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python PyMuPDF如何实现PDF与图片和PPT相互转...
    99+
    2023-07-04
  • android图片类型之间相互转换实现代码
    本文实例讲述了android图片类型之间相互转换实现代码。分享给大家供大家参考。具体如下: android在处理一写图片资源的时候,会进行一些类型的转换,现在有空整理一下: 1...
    99+
    2022-06-06
    Android
  • Python实现图片和视频的相互转换
    目录使用背景一、视频转图像二、图像转视频使用背景 有时候我们需要把很多的图片合成视频,或者说自己写一个脚本去加快或者放慢视频; 也有时候需要把视频裁剪成图片,进行后续操作。 这里提供...
    99+
    2022-11-12
  • Python实现文字pdf转换图片pdf效果
    目录前言思路代码展示前言 为什么会做这个? 因为我们把word转化为pdf,wps默认转化为文字pdf,而图片pdf要会员。 网上确实也有网站可以实现免费的,但是未必安全。 思路 我...
    99+
    2022-11-13
  • android中怎么将图片路径与Uri相互转换
    android中怎么将图片路径与Uri相互转换?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。一个android文件的Uri地址一般如下: content://media/ext...
    99+
    2023-05-31
    android uri 相互
  • Python怎么实现图片和视频的相互转换
    本篇内容主要讲解“Python怎么实现图片和视频的相互转换”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python怎么实现图片和视频的相互转换”吧!使用背景有时候我们需要把很多的图片合成视频,...
    99+
    2023-06-22
  • Java图片与二进制相互转换怎么实现
    这篇文章主要介绍了Java图片与二进制相互转换怎么实现的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Java图片与二进制相互转换怎么实现文章都会有所收获,下面我们一起来看看吧。1、下面是一个完整的代码示例指定文...
    99+
    2023-07-05
  • 关于JAVA11中图片与BASE64相互转换的实现
    由于jdk 1.8 之后sun.misc 包下的 BASE64Decode的依赖 被移除 我们需要在自己的项目中引入EncodeUtils 工具类 帮助我们进行转换 public...
    99+
    2022-11-12
  • JAVA11中图片与BASE64相互转换的实现方法
    这篇文章主要介绍了JAVA11中图片与BASE64相互转换的实现方法,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。常用的java框架有哪些1.SpringMVC,Spring...
    99+
    2023-06-14
  • Python怎么实现文字pdf转换图片pdf效果
    本篇内容主要讲解“Python怎么实现文字pdf转换图片pdf效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python怎么实现文字pdf转换图片pdf效果”吧!代码展示先安装依赖pip&n...
    99+
    2023-06-29
  • 如何用ADO.NET实现txt与Excel的互相转换
    本篇文章为大家展示了如何用ADO.NET实现txt与Excel的互相转换,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。在园子里看过很多文章,关于设计模式,关于架构等等,我在这里谈谈一些软件的功能,为...
    99+
    2023-06-17
  • Java图片与二进制相互转换实现示例讲解
    目录1、下面是一个完整的代码示例2、如何判断 base64 图片的格式3、将网络图片转为 base64 字符串4、将 base64 字符串转为图片输出5、将文件转为 base64 字...
    99+
    2023-03-19
    Java图片与二进制转换 Java图片转换二进制
  • js前端实现word excel pdf ppt mp4图片文本等文件预览
    目录前言实现方案docx文件实现前端预览代码实现实现效果pdf实现前端预览代码实现实现效果excel实现前端预览代码实现实现效果pptx的前端预览实现效果总结前言 因为业务需要,很多...
    99+
    2022-11-13
  • android中怎么实现String与InputStream相互转换
    android中怎么实现String与InputStream相互转换,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。一:纯手戳代码:String to InputStreamSt...
    99+
    2023-06-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作