尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

常见文件格式转国产ofd案例,支持pdf、word、txt;

常见文件格式转国产ofd案例,支持pdf、word、txt;
📅 发布时间:2026/6/19 18:12:44

importcom.spire.doc.Document;importcom.spire.doc.FileFormat;importcom.spire.pdf.PdfDocument;importjava.io.*;public class DesktopConverter{public static void main(String[]args){//1. 配置路径 String sourceFolderPath="C:\\Users\\qinqin\\Desktop";String outputFolderPath="C:\\Users\\qinqin\\Desktop\\ofd_output";//2. 创建输出目录 File outputDir=new File(outputFolderPath);if(!outputDir.exists()){outputDir.mkdirs();System.out.println("已创建输出目录: "+ outputFolderPath);}//3. 扫描文件 File sourceDir=new File(sourceFolderPath);File[]files=sourceDir.listFiles();if(files==null||files.length==0){System.out.println("目录下没有文件!");return;}System.out.println("=== 开始批量转换 ===");for(Filefile:files){if(file.isDirectory())continue;// 跳过文件夹 String fileName=file.getName();String lowerName=fileName.toLowerCase();String srcPath=file.getAbsolutePath();// 生成输出文件名(例如:1.doc ->1_doc.ofd)String outName=fileName.replace(".","_")+".ofd";String destPath=outputFolderPath + File.separator + outName;try{if(lowerName.endsWith(".doc")||lowerName.endsWith(".docx")){System.out.print("正在转换 Word: "+ fileName +" ... ");convertWordToOfd(srcPath, destPath);System.out.println("✅ 成功");}elseif(lowerName.endsWith(".txt")){System.out.print("正在转换 Txt: "+ fileName +" ... ");convertTxtToOfd(srcPath, destPath);System.out.println("✅ 成功");}elseif(lowerName.endsWith(".pdf")){System.out.print("正在转换 PDF: "+ fileName +" ... ");convertPdfToOfd(srcPath, destPath);System.out.println("✅ 成功");}}catch(Exception e){System.out.println("❌ 失败 ("+ e.getMessage()+")");e.printStackTrace();}}System.out.println("=== 全部完成,请查看文件夹: "+ outputFolderPath +" ===");}// --- 核心转换方法 --- /** * Word/Docx 转 OFD */ public static void convertWordToOfd(String srcPath, String destPath)throws Exception{Document doc=new Document();doc.loadFromFile(srcPath);// Word 转 PDF 流 ByteArrayOutputStream pdfStream=new ByteArrayOutputStream();doc.saveToStream(pdfStream, FileFormat.PDF);// PDF 流转 OFD streamToOfd(new ByteArrayInputStream(pdfStream.toByteArray()), destPath);}/** * Txt 转 OFD */ public static void convertTxtToOfd(String srcPath, String destPath)throws Exception{Document doc=new Document();// 显式指定加载格式为 Text doc.loadFromFile(srcPath, FileFormat.Txt);ByteArrayOutputStream pdfStream=new ByteArrayOutputStream();doc.saveToStream(pdfStream, FileFormat.PDF);streamToOfd(new ByteArrayInputStream(pdfStream.toByteArray()), destPath);}/** * PDF 转 OFD */ public static void convertPdfToOfd(String srcPath, String destPath){PdfDocument pdf=new PdfDocument();pdf.loadFromFile(srcPath);pdf.saveToFile(destPath, com.spire.pdf.FileFormat.OFD);pdf.close();}/** * 通用:内存PDF流 ->OFD文件 */ private static void streamToOfd(InputStream inputStream, String destPath){PdfDocument pdf=new PdfDocument();pdf.loadFromStream(inputStream);pdf.saveToFile(destPath, com.spire.pdf.FileFormat.OFD);pdf.close();}}

相关新闻

  • python智能停车场车位租赁管理系统vue
  • 【JPCS出版 | EI检索】第七届新材料与清洁能源国际学术会议(ICAMCE 2026)
  • 2025年口碑好的美甲培训学校推荐,专业美甲课程与就业支持全解析 - 工业推荐榜

最新新闻

  • 告别GUI开发噩梦:用Dear ImGui在30分钟内为C++项目添加专业界面
  • 这些工具助你轻松下载抖音别人的作品,省时省力 - 工具软件使用方法推荐
  • 钻石回收避坑干货2026 天津,实地探店多家商家,禹竞名奢汇资质正规结算快 - 名奢变现站
  • 如何快速掌握B站工具箱:面向新手的完整免费下载指南
  • Upgrade Win11 subsystem Ubuntu22.04 to ubuntu24.04
  • 2026合肥理工学校职教高考班招生详情|中考200-450分升学通道 - cc江江

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号