0
点赞
收藏
分享

微信扫一扫

【机器学习】探索机器学习在旅游业的革新之旅

mjjackey 2024-08-23 阅读 23

前言

本文介绍使用 Java 调用 aspose-cells、aspose-pdf 可方便的实现:

  • excel 文件转化为 html、pdf 文件
  • 多个 pdf 进行合并
  • pdf 提取文字
  • pdf 拆分
  • pdf 转换为 word

所有代码和使用方法已经上传 github 和码云 ,可自行选择任意一种下载项目使用:

  • github 项目地址 ExcelPdfCoverUtils
  • 码云项目地址 ExcelPdfCoverUtils

下面只简单介绍下使用方法。


一、excel 文件转换为 html

        String excelPath = "C:\\Users\\haitang\\Downloads\\bbb.xlsx";
        String htmlPath = "C:\\Users\\haitang\\Downloads\\cover\\myExcel.html";
        ExcelCoverUtils.excelTohtml(excelPath, htmlPath);

二、excel 文件转换为 pdf

  1. excel 文件里的所有 sheet 转化为 pdf
        String excelPath = "C:\\Users\\haitang\\Downloads\\bbb.xlsx";
        String pdfPath = "C:\\Users\\haitang\\Downloads\\cover\\myExcel.pdf";
        ExcelCoverUtils.excelToPdf(excelPath, pdfPath);
  1. excel 文件里选择指定的 sheet 转化为 pdf
        String excelPath = "C:\\Users\\haitang\\Downloads\\bbb.xlsx";
        String pdfPath = "C:\\Users\\haitang\\Downloads\\cover\\myExcel.pdf";
        //选择第1、3、4 个sheet页面转化为pdf (sheet页面从0开始)
        ExcelCoverUtils.excelToPdf(excelPath, pdfPath,new int[]{0,2,3});

三、pdf 合并

        //待合并的pdf文件
        String pdf1 = "C:\\Users\\haitang\\Downloads\\test.pdf";
        String pdf2 = "C:\\Users\\haitang\\Downloads\\effective-java-2.pdf";
        List<String> pdfPaths = Arrays.asList(pdf1, pdf2);
        //合并为一个pdf
        PdfCoverUtils.pdfMergePdf(pdfPaths, "C:\\myCode\\mavenTest\\merge.pdf");

四、pdf 提取文字内容到 txt

        String pdf = "C:\\Users\\haitang\\Downloads\\effective-java-2.pdf";
        PdfCoverUtils.pdfGetContent(pdf,"C:\\myCode\\mavenTest\\pdfContent.txt");

五、pdf 拆分

        String pdf = "C:\\Users\\haitang\\Downloads\\effective-java-2.pdf";
        //获取原pdf文件的第2到第5页为一个新的pdf  
        PdfCoverUtils.getNewPdfRange(pdf,2,5,"C:\\myCode\\mavenTest\\newPdf.pdf");

六、pdf 转换为 word

        String pdf = "C:\\Users\\haitang\\Downloads\\effective-java-2.pdf";
        PdfCoverUtils.convertPDFtoWord(pdf,"C:\\myCode\\mavenTest\\word.docx");
举报

相关推荐

0 条评论