|
1 | | -# wps2pdf |
| 1 | +# doc2pdf |
2 | 2 |
|
3 | | -> 命令行工具,将 WPS / Microsoft Office 文档(.doc/.docx)转换为 PDF。 |
| 3 | +> A command-line tool to convert WPS / Microsoft Office documents (.doc/.docx) to PDF. |
4 | 4 |
|
5 | 5 | [](https://github.com/lilucpp/doc2pdf) |
6 | 6 | [](https://isocpp.org/) |
7 | 7 | [](https://cmake.org/) |
8 | 8 | [](LICENSE) |
9 | 9 |
|
10 | | -## 特性 |
| 10 | +## Features |
11 | 11 |
|
12 | | -- **无需打印机驱动** — 通过 COM 自动化调用 WPS / Office 原生导出 API |
13 | | -- **自动检测** — 优先使用 WPS,回退到 Microsoft Word |
14 | | -- **支持页面范围** — 可指定起始/结束页码 |
15 | | -- **轻量** — 单 exe,无外部运行时依赖(静态链接 /MT) |
16 | | -- **兼容 32/64 位系统** — 推荐 32 位构建以兼容大多数 WPS/Office 安装 |
| 12 | +- **No printer driver required** — Uses COM automation to call the native export API of WPS / Office |
| 13 | +- **Auto-detection** — Prefers WPS, falls back to Microsoft Word |
| 14 | +- **Page range support** — Specify start/end page numbers |
| 15 | +- **Lightweight** — Single exe, no external runtime dependencies (static link /MT) |
| 16 | +- **32/64-bit compatible** — 32-bit build recommended for maximum WPS/Office compatibility |
17 | 17 |
|
18 | | -## 实现原理 |
| 18 | +## How It Works |
19 | 19 |
|
20 | | -通过 **COM 自动化** 调用应用程序的 `ExportAsFixedFormat` API,无需任何中间件或虚拟打印机。 |
| 20 | +Uses **COM automation** to invoke the application's `ExportAsFixedFormat` API, no middleware or virtual printer needed. |
21 | 21 |
|
22 | | -## 兼容性 |
| 22 | +## Compatibility |
23 | 23 |
|
24 | | -| 应用程序 | ProgID | 要求 | |
25 | | -|----------|--------|------| |
26 | | -| **WPS Office** (推荐) | `KWps.Application` | WPS Office 已安装 | |
27 | | -| **Microsoft Office Word 2007** | `Word.Application` | 需 **SP2** 或安装 [Save as PDF 插件](http://www.microsoft.com/downloads/details.aspx?familyid=4d951911-3e7e-4ae6-b059-a2e79ed87041) | |
28 | | -| **Microsoft Office Word 2010+** | `Word.Application` | 原生支持,无需额外组件 | |
29 | | -| **Microsoft Office 365** | `Word.Application` | 原生支持 | |
| 24 | +| Application | ProgID | Requirements | |
| 25 | +|-------------|--------|-------------| |
| 26 | +| **WPS Office** (recommended) | `KWps.Application` | WPS Office installed | |
| 27 | +| **Microsoft Office Word 2007** | `Word.Application` | Requires **SP2** or [Save as PDF add-in](http://www.microsoft.com/downloads/details.aspx?familyid=4d951911-3e7e-4ae6-b059-a2e79ed87041) | |
| 28 | +| **Microsoft Office Word 2010+** | `Word.Application` | Native support, no additional components | |
| 29 | +| **Microsoft Office 365** | `Word.Application` | Native support | |
30 | 30 |
|
31 | | -> 程序启动顺序:先尝试 WPS → 失败则尝试 Office Word → 都失败则报错退出。 |
| 31 | +> Startup order: tries WPS first → falls back to Office Word → exits with error if both fail. |
32 | 32 |
|
33 | | -## 使用 |
| 33 | +## Usage |
34 | 34 |
|
35 | 35 | ``` |
36 | | -wps2pdf <输入文件> [-o 输出文件] [-f 起始页] [-t 结束页] |
| 36 | +doc2pdf <input file> [-o output file] [-f from page] [-t to page] |
37 | 37 | ``` |
38 | 38 |
|
39 | | -| 参数 | 说明 | |
40 | | -|------|------| |
41 | | -| `-o` / `--output` | 输出 PDF 路径(默认:输入文件同名.pdf) | |
42 | | -| `-f` / `--from` | 起始页码(默认:第 1 页) | |
43 | | -| `-t` / `--to` | 结束页码(默认:最后一页,需同时指定 `-f`) | |
| 39 | +| Argument | Description | |
| 40 | +|----------|-------------| |
| 41 | +| `-o` / `--output` | Output PDF path (default: input file name with .pdf extension) | |
| 42 | +| `-f` / `--from` | Start page (default: page 1) | |
| 43 | +| `-t` / `--to` | End page (default: last page; requires `-f`) | |
44 | 44 |
|
45 | | -### 示例 |
| 45 | +### Examples |
46 | 46 |
|
47 | 47 | ```powershell |
48 | | -wps2pdf 1.docx # 全部页面 |
49 | | -wps2pdf 1.docx -f 2 -t 5 # 第 2-5 页 |
50 | | -wps2pdf 1.docx -f 3 # 从第 3 页到末尾 |
51 | | -wps2pdf 1.docx -o D:\out.pdf # 指定输出路径 |
| 48 | +doc2pdf 1.docx # All pages |
| 49 | +doc2pdf 1.docx -f 2 -t 5 # Pages 2-5 |
| 50 | +doc2pdf 1.docx -f 3 # From page 3 to end |
| 51 | +doc2pdf 1.docx -o D:\out.pdf # Specify output path |
52 | 52 | ``` |
53 | 53 |
|
54 | | -## 编译 |
| 54 | +## Build |
55 | 55 |
|
56 | | -### 要求 |
| 56 | +### Requirements |
57 | 57 |
|
58 | | -- Visual Studio 2022 Build Tools(或完整版 VS) |
| 58 | +- Visual Studio 2022 Build Tools (or full VS) |
59 | 59 | - CMake 3.10+ |
60 | 60 |
|
61 | | -### 构建(32 位,静态链接 /MT) |
| 61 | +### Build (32-bit, static link /MT) |
62 | 62 |
|
63 | 63 | ```powershell |
64 | 64 | cmake -G "Visual Studio 17 2022" -A Win32 -B build |
65 | 65 | cmake --build build --config Release |
66 | 66 | ``` |
67 | 67 |
|
68 | | -产物在 `build\Release\wps2pdf.exe`,不依赖 VC 运行时库。 |
| 68 | +Output at `build\Release\doc2pdf.exe`, no VC runtime dependencies. |
69 | 69 |
|
70 | | -### 架构说明 |
| 70 | +### Architecture Notes |
71 | 71 |
|
72 | | -工具编译为 32 位,通过 COM 调用 WPS/Office。32 位工具只能调用 32 位的 WPS/Office(64 位系统上这是最常见的安装方式)。 |
| 72 | +The tool is compiled as 32-bit and uses COM to call WPS/Office. A 32-bit tool can only call 32-bit WPS/Office (the most common installation on 64-bit systems). |
73 | 73 |
|
74 | | -若需支持纯 64 位 Office,请用 `-A x64` 额外编译 64 位版本: |
| 74 | +To support native 64-bit Office, also build a 64-bit version with `-A x64`: |
75 | 75 |
|
76 | 76 | ```powershell |
77 | 77 | cmake -G "Visual Studio 17 2022" -A x64 -B build64 |
78 | 78 | cmake --build build64 --config Release |
79 | 79 | ``` |
80 | 80 |
|
81 | | -## 相关关键词 |
| 81 | +## Keywords |
82 | 82 |
|
83 | | -`doc2pdf` `docx2pdf` `wps2pdf` `word转pdf` `wps转pdf` `office转pdf` `命令行pdf转换` |
| 83 | +`doc2pdf` `docx2pdf` `word to pdf` `wps to pdf` `office to pdf` `command line pdf converter` |
84 | 84 |
|
85 | | -## 许可证 |
| 85 | +## License |
86 | 86 |
|
87 | 87 | [MIT](LICENSE) |
0 commit comments