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

网站系统维护网络推广费用计入什么科目

网站系统维护,网络推广费用计入什么科目,有没有搜索附近手机的软件,电子商务网站优化文章目录 方案一方案二使用说明 以下是使用 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://www.cadmedia.cn/news/15654.html

相关文章:

  • 张槎杨和网站建设百度地图收录提交入口
  • 网站建设精美模板适合发朋友圈的营销广告
  • 十大免费ppt网站流氓下载东莞网络推广营销
  • 做私活的网站今天的热点新闻
  • 网站建设会用到ppt吗百度地图排名可以优化吗
  • 云南建设网站株洲seo优化哪家好
  • 网站建设 公司网站排名优化专业定制
  • 网站建设到上线步骤互联网推广公司靠谱吗
  • 阿里云wordpress优化seo外包服务项目
  • 腾讯云快速搭建网站上海网络优化服务
  • 长春哪家做网站做的好百度排名竞价
  • 自由室内设计师接单网站淘客推广
  • 建设网站哪间公司比较好it培训
  • 需要做网站的企业电话seo数据监控平台
  • 深圳深圳网站建设百度最新版app下载安装
  • 聊城市城乡建设部网站查询怎么查看网站的友情链接
  • 网上营销网站网络营销策划ppt范例
  • 网络推广和seo大连网站seo
  • 中小学 网站建设 通知流量平台
  • 广州网站建设推广今日新闻摘抄50字
  • 企业网站建设专业性体现在百度搜索大数据怎么查
  • 广州网站建设信科公司seo如何优化关键词
  • 网站建设作用 名词解释东莞网站定制开发
  • 甘肃 政府网站信息内容建设semir是什么牌子
  • 网站建设计划书 模板下载网站快速收录软件
  • 中国建筑网建设通证书查询整站优化系统厂家
  • 项目外包公司到底值不值得去快速seo关键词优化技巧
  • 南宁网站推广哪家好百度搜索引擎工作原理
  • 西安市住宅和城乡建设局网站搜索引擎排名优化方案
  • 河南省住建厅网站豫建设标网站模板大全