当前位置: 首页 > wzjs >正文

网站图片展示方式有哪些logo设计公司 北京

网站图片展示方式有哪些,logo设计公司 北京,wordpress 分类模板,网站数据库文件名文章目录 方案一方案二使用说明 以下是使用 Java 实现批量 PDF 转 Word 的两种解决方案,根据需求选择适合的方式: 方案一 使用 Apache PDFBox Apache POI (仅提取文本) 适用场景:仅需提取文本内容(不支持图片/表格/格式保留&…

文章目录

  • 方案一
  • 方案二
  • 使用说明

以下是使用 Java 实现批量 PDF 转 Word 的两种解决方案,根据需求选择适合的方式:

方案一

使用 Apache PDFBox + Apache POI (仅提取文本)
适用场景:仅需提取文本内容(不支持图片/表格/格式保留)

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.poi.xwpf.usermodel.*;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class PdfToWordConverter {  public static void main(String[] args) {       String inputDir = "path/to/pdf/folder";        String outputDir = "path/to/word/folder";               try {                                         Files.createDirectories(Paths.get(outputDir));          File[] pdfFiles = new File(inputDir).listFiles((dir, name) -> name.endsWith(".pdf"));                        if (pdfFiles != null) {                for (File pdfFile : pdfFiles) {                   String wordPath = outputDir + File.separator +      pdfFile.getName().replace(".pdf", ".docx");                    convertPdfToWord(pdfFile.getAbsolutePath(), wordPath);                   System.out.println("转换成功: " + pdfFile.getName());               }            }       } catch (Exception e) {            e.printStackTrace();        }   }    
private static void convertPdfToWord(String pdfPath, String wordPath) throws Exception {        try (PDDocument pdfDoc = PDDocument.load(new File(pdfPath));            XWPFDocument wordDoc = new XWPFDocument()) {                        PDFTextStripper stripper = new PDFTextStripper();            String text = stripper.getText(pdfDoc);                        // 将文本写入Word           try (FileOutputStream out = new FileOutputStream(wordPath)) {               XWPFParagraph paragraph = wordDoc.createParagraph();                XWPFRun run = paragraph.createRun();       run.setText(text);                wordDoc.write(out);            }        }    }}

方案二

调用 LibreOffice 命令行 (推荐,保留格式)
适用场景:需要保留原始格式、图片、表格等(需安装 LibreOffice)

  1. 安装 LibreOffice
  • Windows:下载安装包 https://www.libreoffice.org/
  • macOS: brew install libreoffice
  • Linux: sudo apt install libreoffice
  1. Java 代码
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class PdfToWordLibreOffice {    public static void main(String[] args) {       String inputDir = "path/to/pdf/folder";        String outputDir = "path/to/word/folder";                try {            Files.createDirectories(Paths.get(outputDir));            File[] pdfFiles = new File(inputDir).listFiles((dir, name) -> name.endsWith(".pdf"));                      if (pdfFiles != null) {               for (File pdfFile : pdfFiles) {                    convertWithLibreOffice(pdfFile.getAbsolutePath(), outputDir);                    System.out.println("转换成功: " + pdfFile.getName());                }           }        } catch (Exception e) {            e.printStackTrace();       }   }    private static void convertWithLibreOffice(String pdfPath, String outputDir) throws IOException, InterruptedException {      // 根据系统调整命令路径       
String     command;
if(System.getProperty("os.name").toLowerCase().contains("win")) {            
command = "\"C:\\Program Files\\LibreOffice\\program\\soffice.exe\" --convert-to docx --outdir ";       } else {           command = "libreoffice --headless --convert-to docx:MS Word 2007 XML --outdir ";        }               ProcessBuilder builder = new ProcessBuilder();       builder.command(command + "\"" + outputDir + "\" \"" + pdfPath + "\"");       
builder.directory(newFile(System.getProperty("user.home")));                
Process process = builder.start();       int exitCode = process.waitFor();               if (exitCode != 0) {            throw new IOException("转换失败,退出码: " + exitCode);       }    }}

使用说明

  1. 方案一(PDFBox+POI)
  • 优点:纯 Java 实现,无需外部依赖
  • 缺点:仅提取文本,丢失所有格式
  • 依赖(Maven):
<dependencies>         <dependency>                     <groupId>org.apache.pdfbox</groupId>             <artifactId>pdfbox</artifactId>             <version>2.0.29</version>         </dependency>         <dependency>             <groupId>org.apache.poi</groupId>             <artifactId>poi-ooxml</artifactId>             <version>5.2.3</version>         </dependency>    </dependencies>     ```2. **方案二(LibreOffice)** 
- **优点**:保留原始格式,转换质量高   
- **缺点**:需安装 LibreOffice   
- **命令调整**:    - Windows:确保 `soffice.exe` 路径正确     - Linux/macOS:终端直接执行 `libreoffice --version` 测试是否安装成功
# 执行步骤
1. 将代码中的路径替换为实际 PDF 文件夹和输出文件夹
2. 根据选择的方案添加依赖或安装 LibreOffice
3. 运行程序,查看目标文件夹生成的 Word 文件> **注意**:批量转换大量文件时,建议增加错误处理机制(如文件名合法性检查、转换失败重试等)。对于复杂格式的 PDF,商业库(如 Aspose.PDF)效果更好,但需要付费。

文章转载自:

http://3lDVvPiL.hmpxn.cn
http://LXdBc31t.hmpxn.cn
http://vM3yk2nq.hmpxn.cn
http://PJZj6UEA.hmpxn.cn
http://hGOmh0ET.hmpxn.cn
http://2GRLbhaa.hmpxn.cn
http://iCyuhgTY.hmpxn.cn
http://be0LtpT9.hmpxn.cn
http://XvfErIeV.hmpxn.cn
http://9zy1DM22.hmpxn.cn
http://I9wLfzhT.hmpxn.cn
http://TXn59GwL.hmpxn.cn
http://PzNseSmJ.hmpxn.cn
http://gpaoCrRB.hmpxn.cn
http://KRktti4B.hmpxn.cn
http://TkWXToFi.hmpxn.cn
http://PlXgbkB7.hmpxn.cn
http://Odj4S36g.hmpxn.cn
http://y9Onz0Xs.hmpxn.cn
http://ZhpfKuVW.hmpxn.cn
http://X2uEjJJY.hmpxn.cn
http://haIfWg0D.hmpxn.cn
http://d2g2waLP.hmpxn.cn
http://Gp29WZX0.hmpxn.cn
http://iSaYg12G.hmpxn.cn
http://xT1zFSrD.hmpxn.cn
http://YRvGAqHP.hmpxn.cn
http://BN32UCCP.hmpxn.cn
http://y5r0wiMG.hmpxn.cn
http://6XExlK2V.hmpxn.cn
http://www.dtcms.com/wzjs/631404.html

相关文章:

  • 攻略网站的建设金属材料网站建设
  • 专门装修的网都有什么网网站网站建设洽谈
  • 设计感十足的网站福田庆三鞠婧祎
  • 做网站运营难吗网页游戏推荐排行
  • 国外主流媒体网站wordpress 页面添加图标
  • 做网站的s标的软件网页设计实例
  • 文章类网站程序宁波建设监理协会
  • wordpress 浮框河北seo基础入门教程
  • 网站网站做维护犯罪自助建站免费自助建站网站
  • 详情页模板哪个网站好做的阿里巴巴网站的放哪个科目
  • 深圳flash网站建设如何开发网站建设业务
  • 做微信用什么网站58网站建设58xiamen
  • 重庆市建设岗培中心网站密云做网站的
  • 行业网站系统中国交通建设官方网站
  • 做一家公司网站要注意哪些手机制作ppt哪种软件好
  • 微信自助建站系统c2c模式类型
  • 全国工商网站查询企业信息h5网页制作代码
  • 电影网站可以备案吗男女做暖暖视频网站
  • 湖南环达公路桥梁建设总公司网站网站建设推广小王熊掌号
  • 微信的官方网站怎么做wordpress最近更新文章插件
  • qq刷会员建设网站电商网站建设是做什么的
  • 外贸网站建设需要注意什么广州建网站技术
  • 松江网站建设培训费用徐州建站推广
  • 问卷调查网站赚钱怎么把店地址申请百度地图
  • 自助建站申请书托管网站
  • 广播电视网站建设怎么做原创短视频网站
  • 哪个网站可以做翻译兼职太原代理记账公司
  • 网站的框架3000块钱在朋友圈投放广告
  • 排名seo软件seo优化专家
  • 排名好的青岛网站建设专业网站建设定制公司哪家好