广告
返回顶部
首页 > 资讯 > 精选 >Android怎么实现excel/pdf/word/odt/图片相互转换
  • 732
分享到

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

2023-07-06 03:07:04 732人浏览 安东尼
摘要

本篇内容主要讲解“Android怎么实现excel/pdf/Word/odt/图片相互转换”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android怎么实现excel/pdf/word/odt

本篇内容主要讲解“Android怎么实现excel/pdf/Word/odt/图片相互转换”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android怎么实现excel/pdf/word/odt/图片相互转换”吧!

实践过程

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/图片相互转换”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

--结束END--

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

本文链接: https://www.lsjlt.com/news/357471.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文档相互转换
    本篇内容介绍了“C#怎么实现Word和ODT文档相互转换”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!ODT文档格式一种开放文档格式(Ope...
    99+
    2023-06-30
  • 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
  • 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
  • Python怎么实现文字pdf转换图片pdf效果
    本篇内容主要讲解“Python怎么实现文字pdf转换图片pdf效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python怎么实现文字pdf转换图片pdf效果”吧!代码展示先安装依赖pip&n...
    99+
    2023-06-29
  • android中怎么实现String与InputStream相互转换
    android中怎么实现String与InputStream相互转换,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。一:纯手戳代码:String to InputStreamSt...
    99+
    2023-06-02
  • js中怎么实现file、bolb、base64图片之间的相互转化
    这篇文章主要介绍“js中怎么实现file、bolb、base64图片之间的相互转化”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“js中怎么实现file、bolb、base64图片之间的相互转化”文章...
    99+
    2023-06-30
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作