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();}}常见文件格式转国产ofd案例,支持pdf、word、txt;
张小明
前端开发工程师
探索Mistral-7B-Instruct-v0.2在 Atlas 800T上的推理部署
前言:最近在 GitCode 的 Notebook 环境里玩大模型,想着试试看 Mistral-7B-Instruct-v0.2 在 Atlas 800T 上到底能跑成啥样。结果比我想象的顺利太多,但也踩了几个坑。为了方便大家直接上手,我把整个过程整理成了这篇教程ÿ…
【AI】MCP、A2A和Skills:Agentic AI的最核心基础设施
这三个概念是 2024-2025 年 AI Agent 爆发期最核心的“基础设施”。它们分别解决了 Agent 生态中**“怎么连工具”、“怎么连同行”和“怎么学本事”**这三个根本性问题。 用一个人类职场的类比来解释最直观:概念全称职场类比解决的核心问题MCPModel Context Protoc…
Ryuko-NEHT Reloaded! MAME 0.116 游戏列表与ROM信息
Ryuko-NEHT Reloaded! MAME 0.116 游戏列表与ROM信息 在复古游戏爱好者圈层中,精准识别和管理海量街机 ROM 是一个长期存在的挑战。尤其当面对像 MAME(Multiple Arcade Machine Emulator) 这样覆盖数万款历史机型的庞大生态时,如何…
阅文大神作者真容曝光:天蚕土豆最帅?
阅文大神作者真容曝光:天蚕土豆最帅? 最近翻阅文集团那个“作家抗疫加油”的合集视频时,突然手痒——这些我们天天追更、如雷贯耳的网文大神,现实中到底长啥样?能不能从视频里把他们的脸和信息“抠”出来看看…
Excel随机数生成与分布详解
lora-scripts 使用指南:从数据到智能行为的“分布生成” 在 AI 微调的世界里,我们常常面对一个问题:如何让一个通用模型变得“懂我”? 答案是——训练一个专属的 LoRA 模型。但传统方式需要写一堆代码、配环境、调参数,…
PDCA循环详解:四阶段八步骤实战指南
PDCA循环详解:四阶段八步骤实战指南 在AI模型部署日益频繁的今天,一个常见的困境是:明明技术指标达标,用户却抱怨“识别太慢”“结果不准”。这种体验与性能之间的落差,往往不是因为算法不够先进,而是缺乏一…