diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..63b1e4e5ec8adc29e277d12372f08d53ee2e5cdf --- /dev/null +++ b/README.en.md @@ -0,0 +1,116 @@ +# File Conversion Helper + +File Conversion Helper - A Java-based file conversion toolkit supporting mutual conversion between Word documents and PDFs, along with embedded Word document parsing functionality. + +## Project Overview + +This project is a Java library focused on file format conversion, with the following main features: + +- **Word to PDF**: Convert Word documents (.docx) to PDF format +- **PDF to Word**: Convert PDF documents to Word format +- **Create Word Documents**: Dynamically generate Word documents using FreeMarker templates +- **Embedded Word Parsing**: Parse embedded content within Word documents to extract resources such as XML and images + +## Technology Stack + +- **Apache POI**: For handling Office document formats +- **FreeMarker**: Template engine for dynamic document generation +- **Maven**: Project build and management + +## Project Structure + +``` +fileHelper/ +├── pom.xml # Maven configuration file +├── src/main/java/com/study/ +│ ├── Test01.java # Functional test class +│ ├── entity/dto/ +│ │ └── EmbedWordParseDto.java # Data transfer object for embedded Word parsing +│ └── utils/ +│ └── FileConvertUtils.java # Core file conversion utility class +└── src/main/resources/ + └── template/ + └── monitor_report.ftl # FreeMarker template file +``` + +## Core Features + +### 1. Word to PDF +```java +File wordFile = new File("input.docx"); +File pdfFile = FileConvertUtils.wordToPdfUpload(wordFile); +``` + +### 2. Create Word Document +```java +Map dataMap = new HashMap<>(); +dataMap.put("title", "Monitoring Report"); +dataMap.put("content", "Report content..."); +File wordFile = FileConvertUtils.createWord(dataMap, "monitor_report.ftl", "/output", "report.docx"); +``` + +### 3. Parse Embedded Word +```java +File embedWordFile = new File("embedded.docx"); +EmbedWordParseDto result = FileConvertUtils.parseEmbedWord(embedWordFile); +String detailXml = result.getDetailXml(); +List> images = result.getImageMapList(); +List rels = result.getNewRealList(); +``` + +## Quick Start + +### Prerequisites + +- JDK 1.8+ +- Maven 3.0+ + +### Install Dependencies + +```bash +mvn clean install +``` + +### Run Tests + +```bash +mvn test +``` + +## API Documentation + +### FileConvertUtils + +#### parseEmbedWord +```java +public static EmbedWordParseDto parseEmbedWord(File embedWordFile) throws Exception +``` +Parses an embedded Word document and returns a data object containing XML content, a list of image mappings, and a list of relationships. + +#### createWord +```java +public static File createWord(Map dataMap, String templateName, String filePath, String fileName) +``` +Creates a Word document based on a FreeMarker template. + +#### wordToPdfUpload +```java +public static File wordToPdfUpload(File wordFile) +``` +Converts a Word document to PDF format. + +### EmbedWordParseDto + +| Property | Type | Description | +|----------|------|-------------| +| detailXml | String | Parsed XML content | +| imageMapList | List> | List of image mappings | +| newRealList | List | List of new relationships | + +## License + +This project is licensed under an open-source license. + +## Contribution Guidelines + +Issues and pull requests are welcome to help improve this project. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cdddb606a118d4da01c8847c30ac7dc2d9c5aff6 --- /dev/null +++ b/README.md @@ -0,0 +1,118 @@ + + +# File Conversion Helper + +文件转换助手 - 基于Java的文件转换工具集,支持Word文档与PDF之间的相互转换,并提供嵌入式Word文档解析功能。 + +## 项目简介 + +本项目是一个专注于文件格式转换的Java工具库,主要功能包括: + +- **Word转PDF**:将Word文档(.docx)转换为PDF格式 +- **PDF转Word**:将PDF文档转换为Word格式 +- **创建Word文档**:基于FreeMarker模板动态生成Word文档 +- **嵌入式Word解析**:解析嵌入在Word文档中的内容,提取XML、图片等资源 + +## 技术栈 + +- **Apache POI**:处理Office文档格式 +- **FreeMarker**:模板引擎,用于动态生成文档 +- **Maven**:项目构建与管理 + +## 项目结构 + +``` +fileHelper/ +├── pom.xml # Maven配置文件 +├── src/main/java/com/study/ +│ ├── Test01.java # 功能测试类 +│ ├── entity/dto/ +│ │ └── EmbedWordParseDto.java # 嵌入式Word解析数据传输对象 +│ └── utils/ +│ └── FileConvertUtils.java # 文件转换核心工具类 +└── src/main/resources/ + └── template/ + └── monitor_report.ftl # FreeMarker模板文件 +``` + +## 核心功能说明 + +### 1. Word转PDF +```java +File wordFile = new File("input.docx"); +File pdfFile = FileConvertUtils.wordToPdfUpload(wordFile); +``` + +### 2. 创建Word文档 +```java +Map dataMap = new HashMap<>(); +dataMap.put("title", "监控报告"); +dataMap.put("content", "报告内容..."); +File wordFile = FileConvertUtils.createWord(dataMap, "monitor_report.ftl", "/output", "report.docx"); +``` + +### 3. 解析嵌入式Word +```java +File embedWordFile = new File("embedded.docx"); +EmbedWordParseDto result = FileConvertUtils.parseEmbedWord(embedWordFile); +String detailXml = result.getDetailXml(); +List> images = result.getImageMapList(); +List rels = result.getNewRealList(); +``` + +## 快速开始 + +### 环境要求 + +- JDK 1.8+ +- Maven 3.0+ + +### 安装依赖 + +```bash +mvn clean install +``` + +### 运行测试 + +```bash +mvn test +``` + +## API文档 + +### FileConvertUtils + +#### parseEmbedWord +```java +public static EmbedWordParseDto parseEmbedWord(File embedWordFile) throws Exception +``` +解析嵌入式Word文档,返回包含XML内容、图片映射列表和关系列表的数据对象。 + +#### createWord +```java +public static File createWord(Map dataMap, String templateName, String filePath, String fileName) +``` +基于FreeMarker模板创建Word文档。 + +#### wordToPdfUpload +```java +public static File wordToPdfUpload(File wordFile) +``` +将Word文档转换为PDF格式。 + +### EmbedWordParseDto + +| 属性 | 类型 | 说明 | +|------|------|------| +| detailXml | String | 解析后的XML内容 | +| imageMapList | List> | 图片映射列表 | +| newRealList | List | 新的关系列表 | + +## 许可证 + +本项目遵循开源协议。 + +## 贡献指南 + +欢迎提交Issue和Pull Request来帮助改进本项目。 \ No newline at end of file