ppt2fig 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ppt2fig-1.1.0/LICENSE +21 -0
- ppt2fig-1.1.0/PKG-INFO +240 -0
- ppt2fig-1.1.0/README.md +213 -0
- ppt2fig-1.1.0/ppt2fig/__main__.py +4 -0
- ppt2fig-1.1.0/ppt2fig/cli.py +130 -0
- ppt2fig-1.1.0/ppt2fig/core.py +712 -0
- ppt2fig-1.1.0/ppt2fig/gui.py +220 -0
- ppt2fig-1.1.0/ppt2fig/main.py +24 -0
- ppt2fig-1.1.0/ppt2fig.egg-info/PKG-INFO +240 -0
- ppt2fig-1.1.0/ppt2fig.egg-info/SOURCES.txt +14 -0
- ppt2fig-1.1.0/ppt2fig.egg-info/dependency_links.txt +1 -0
- ppt2fig-1.1.0/ppt2fig.egg-info/entry_points.txt +2 -0
- ppt2fig-1.1.0/ppt2fig.egg-info/requires.txt +5 -0
- ppt2fig-1.1.0/ppt2fig.egg-info/top_level.txt +1 -0
- ppt2fig-1.1.0/setup.cfg +4 -0
- ppt2fig-1.1.0/setup.py +30 -0
ppt2fig-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ElliottZheng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ppt2fig-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ppt2fig
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: 导出 PowerPoint 页面为 PDF,支持 Windows GUI 和跨平台 CLI。
|
|
5
|
+
Home-page: https://github.com/elliottzheng/ppt2fig
|
|
6
|
+
Author: Elliot Zheng
|
|
7
|
+
Author-email: admin@hypercube.top
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: comtypes; platform_system == "Windows"
|
|
15
|
+
Requires-Dist: pdfCropMargins
|
|
16
|
+
Requires-Dist: pypdf
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
# PPT2Fig
|
|
29
|
+
|
|
30
|
+
PPT2Fig 是一个用于将 PPT 页面导出为 PDF 并自动裁剪白边的工具。
|
|
31
|
+
|
|
32
|
+
- Windows 下保留原有 GUI,可直接导出当前打开的 PowerPoint 当前页
|
|
33
|
+
- 新增跨平台 CLI,可直接指定 `pptx` 文件路径和页码
|
|
34
|
+
- CLI 不依赖 Microsoft PowerPoint,可自动检测本机候选后端
|
|
35
|
+
|
|
36
|
+
PPT2Fig exports PowerPoint slides to PDF and can automatically crop white margins.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## 功能特点
|
|
41
|
+
|
|
42
|
+
- Windows GUI 一键导出当前 PowerPoint 当前页为 PDF
|
|
43
|
+
- 跨平台 CLI,支持指定 PPT/PPTX/ODP 文件和页码
|
|
44
|
+
- CLI 不依赖 Microsoft PowerPoint
|
|
45
|
+
- 自动检测系统中的候选后端
|
|
46
|
+
- 自动裁剪白边
|
|
47
|
+
- 可展开的高级裁剪设置:
|
|
48
|
+
- 快速预设:紧密裁剪、小白边、中白边、保留原边距
|
|
49
|
+
- 可调整保留原始边距的百分比
|
|
50
|
+
- 可设置额外的白边大小
|
|
51
|
+
- 可调整背景检测阈值
|
|
52
|
+
- 支持统一裁剪和统一页面大小选项
|
|
53
|
+
- Windows GUI 智能记忆上次保存路径
|
|
54
|
+
- Windows GUI 始终置顶显示,方便操作
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## 安装方法
|
|
59
|
+
|
|
60
|
+
1. 直接下载[Releases](https://github.com/elliottzheng/ppt2fig/releases)中的exe文件,双击即可运行
|
|
61
|
+
|
|
62
|
+
2. 如果你有python环境,可以使用pip安装
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install ppt2fig
|
|
66
|
+
```
|
|
67
|
+
然后运行
|
|
68
|
+
```bash
|
|
69
|
+
ppt2fig
|
|
70
|
+
```
|
|
71
|
+
或者
|
|
72
|
+
```bash
|
|
73
|
+
python -m ppt2fig
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
如果你要在 Linux/macOS 上使用 CLI,推荐安装 LibreOffice,并确保命令行里能找到 `soffice` 或 `libreoffice`。
|
|
77
|
+
|
|
78
|
+
## 使用方法
|
|
79
|
+
|
|
80
|
+
### Windows GUI
|
|
81
|
+
|
|
82
|
+
程序运行后会出现一个简洁的界面:
|
|
83
|
+
|
|
84
|
+

|
|
85
|
+
|
|
86
|
+
### 基本使用(适合大多数用户):
|
|
87
|
+
|
|
88
|
+
1. 点击"转PDF"按钮(请确保点击时PowerPoint是打开的)
|
|
89
|
+
2. 选择保存位置并点击"保存",则**当前活跃的PPT页面**会导出为PDF文件并自动裁剪白边
|
|
90
|
+
3. 默认保存路径为当前活跃PPT文件所在目录
|
|
91
|
+
|
|
92
|
+
### 高级设置(需要精细控制时):
|
|
93
|
+
|
|
94
|
+
点击"▼ 显示高级设置"展开详细参数控制:
|
|
95
|
+
|
|
96
|
+
#### 快速设置预设:
|
|
97
|
+
- **紧密裁剪**: 完全去除白边
|
|
98
|
+
- **小白边**: 保留约1mm白边
|
|
99
|
+
- **中白边**: 保留约2mm白边
|
|
100
|
+
- **保留原边距**: 保留10%的原始边距
|
|
101
|
+
|
|
102
|
+
#### 详细参数设置:
|
|
103
|
+
|
|
104
|
+
1. **保留原始边距(%)**: 设置保留原PDF边距的百分比
|
|
105
|
+
- 0% = 完全去除边距(紧密裁剪)
|
|
106
|
+
- 10% = 保留10%的原始边距
|
|
107
|
+
- 适合对有一定边距的PDF进行微调
|
|
108
|
+
|
|
109
|
+
2. **额外白边(bp)**: 在裁剪后额外增加的白边大小
|
|
110
|
+
- 单位为 bp (big points),1bp ≈ 0.35mm
|
|
111
|
+
- 适合需要为图片添加统一白边的场景
|
|
112
|
+
|
|
113
|
+
3. **检测阈值**: 背景检测的阈值设置 (0-255)
|
|
114
|
+
- 默认值191适合大多数情况
|
|
115
|
+
- 值越小检测越严格,适合灰色背景
|
|
116
|
+
- 值越大检测越宽松
|
|
117
|
+
|
|
118
|
+
4. **裁剪选项**:
|
|
119
|
+
- **统一裁剪**: 所有页面使用相同的裁剪量
|
|
120
|
+
- **统一页面大小**: 所有页面设为相同尺寸
|
|
121
|
+
|
|
122
|
+
### CLI
|
|
123
|
+
|
|
124
|
+
CLI 适用于 Linux、macOS、Windows,不依赖 PowerPoint。
|
|
125
|
+
程序会自动检测本机候选后端。
|
|
126
|
+
当前已实现的自动导出后端是:
|
|
127
|
+
|
|
128
|
+
- `LibreOffice`: Windows / Linux / macOS
|
|
129
|
+
- `PowerPoint`: Windows / macOS
|
|
130
|
+
- `WPS`: Windows
|
|
131
|
+
|
|
132
|
+
`--list-backends` 会尽量按当前平台列出已检测到的候选程序,即使该平台暂时还没有实现对应的自动导出驱动。
|
|
133
|
+
在 `auto` 模式下,默认优先级是 `LibreOffice > WPS > PowerPoint`。
|
|
134
|
+
|
|
135
|
+
基本示例:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
ppt2fig ./demo.pptx --pages 3
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
导出多个页码:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
ppt2fig ./demo.pptx --pages 1,3,5-7 -o ./figure.pdf
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
关闭裁剪:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
ppt2fig ./demo.pptx --pages 2 --no-crop
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
指定 LibreOffice 可执行文件:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
ppt2fig ./demo.pptx --pages 4 --office-bin /usr/bin/soffice
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
强制使用 PowerPoint 后端:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
ppt2fig ./demo.pptx --pages 2 --backend powerpoint
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
强制使用 WPS 后端:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
ppt2fig ./demo.pptx --pages 2 --backend wps
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
使用 PowerPoint 的打印质量导出:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
ppt2fig ./demo.pptx --pages 2 --backend powerpoint --powerpoint-intent print
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
查看当前机器检测到的候选后端:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
ppt2fig --list-backends
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
常用参数:
|
|
184
|
+
|
|
185
|
+
- `--pages`: 必填,支持 `1,3,5-7`
|
|
186
|
+
- `--output`: 输出 PDF 路径
|
|
187
|
+
- `--office-bin`: 指定 `soffice` 或 `libreoffice`
|
|
188
|
+
- `--backend`: 选择 `auto`、`libreoffice`、`powerpoint` 或 `wps`
|
|
189
|
+
- `--powerpoint-intent`: PowerPoint 后端使用 `print` 或 `screen`
|
|
190
|
+
- `--bitmap-missing-fonts`: 字体无法嵌入时将文字转为位图
|
|
191
|
+
- `--list-backends`: 查看当前检测到的候选后端
|
|
192
|
+
- `--no-crop`: 不裁剪白边
|
|
193
|
+
- `--percent-retain`: 保留原始边距百分比
|
|
194
|
+
- `--margin-size`: 额外白边,单位 bp
|
|
195
|
+
- `--threshold`: 背景检测阈值
|
|
196
|
+
- `--no-uniform`: 禁用统一裁剪
|
|
197
|
+
- `--no-same-size`: 禁用统一页面大小
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
## 系统要求
|
|
201
|
+
|
|
202
|
+
- GUI:
|
|
203
|
+
- Windows
|
|
204
|
+
- Microsoft PowerPoint
|
|
205
|
+
- CLI:
|
|
206
|
+
- Windows / Linux / macOS
|
|
207
|
+
- 推荐 LibreOffice
|
|
208
|
+
- Python 3.8+
|
|
209
|
+
|
|
210
|
+
## 依赖项(安装时自动安装)
|
|
211
|
+
|
|
212
|
+
- comtypes: Windows GUI 下用于与PowerPoint交互
|
|
213
|
+
- pdfCropMargins: 裁剪PDF白边
|
|
214
|
+
- pypdf: 从导出的整份 PDF 中提取指定页
|
|
215
|
+
- tkinter: Python 自带,仅 GUI 使用
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
## 注意事项
|
|
219
|
+
|
|
220
|
+
- GUI 使用前请确保已经打开 PowerPoint
|
|
221
|
+
- GUI 依赖当前活动演示文稿
|
|
222
|
+
- CLI 会先自动检测候选后端;不同平台上的自动导出支持范围不同
|
|
223
|
+
- `--list-backends` 中的 `detected` 表示发现了候选程序,但当前平台未必已经实现自动导出
|
|
224
|
+
- CLI 当前通过导出整份 PDF 后再抽取指定页,因此页码以导出后的 PDF 页序为准
|
|
225
|
+
- 如果系统里没有可用的 LibreOffice 兼容后端,请安装 LibreOffice 或用 `--office-bin` 显式指定路径
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
## 编译指南
|
|
229
|
+
|
|
230
|
+
1. 下载源码
|
|
231
|
+
2. 创建一个环境,只安装本项目依赖和pyinstaller
|
|
232
|
+
3. 参考[配置upx](https://blog.csdn.net/JiuShu110/article/details/132625538)配置upx,用于压缩exe文件
|
|
233
|
+
4. 编译
|
|
234
|
+
```cmd
|
|
235
|
+
pyinstaller -F -w -n ppt2fig --optimize=2 ppt2fig/main.py
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 许可证
|
|
239
|
+
|
|
240
|
+
[MIT License](LICENSE)
|
ppt2fig-1.1.0/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# PPT2Fig
|
|
2
|
+
|
|
3
|
+
PPT2Fig 是一个用于将 PPT 页面导出为 PDF 并自动裁剪白边的工具。
|
|
4
|
+
|
|
5
|
+
- Windows 下保留原有 GUI,可直接导出当前打开的 PowerPoint 当前页
|
|
6
|
+
- 新增跨平台 CLI,可直接指定 `pptx` 文件路径和页码
|
|
7
|
+
- CLI 不依赖 Microsoft PowerPoint,可自动检测本机候选后端
|
|
8
|
+
|
|
9
|
+
PPT2Fig exports PowerPoint slides to PDF and can automatically crop white margins.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 功能特点
|
|
14
|
+
|
|
15
|
+
- Windows GUI 一键导出当前 PowerPoint 当前页为 PDF
|
|
16
|
+
- 跨平台 CLI,支持指定 PPT/PPTX/ODP 文件和页码
|
|
17
|
+
- CLI 不依赖 Microsoft PowerPoint
|
|
18
|
+
- 自动检测系统中的候选后端
|
|
19
|
+
- 自动裁剪白边
|
|
20
|
+
- 可展开的高级裁剪设置:
|
|
21
|
+
- 快速预设:紧密裁剪、小白边、中白边、保留原边距
|
|
22
|
+
- 可调整保留原始边距的百分比
|
|
23
|
+
- 可设置额外的白边大小
|
|
24
|
+
- 可调整背景检测阈值
|
|
25
|
+
- 支持统一裁剪和统一页面大小选项
|
|
26
|
+
- Windows GUI 智能记忆上次保存路径
|
|
27
|
+
- Windows GUI 始终置顶显示,方便操作
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## 安装方法
|
|
32
|
+
|
|
33
|
+
1. 直接下载[Releases](https://github.com/elliottzheng/ppt2fig/releases)中的exe文件,双击即可运行
|
|
34
|
+
|
|
35
|
+
2. 如果你有python环境,可以使用pip安装
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install ppt2fig
|
|
39
|
+
```
|
|
40
|
+
然后运行
|
|
41
|
+
```bash
|
|
42
|
+
ppt2fig
|
|
43
|
+
```
|
|
44
|
+
或者
|
|
45
|
+
```bash
|
|
46
|
+
python -m ppt2fig
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
如果你要在 Linux/macOS 上使用 CLI,推荐安装 LibreOffice,并确保命令行里能找到 `soffice` 或 `libreoffice`。
|
|
50
|
+
|
|
51
|
+
## 使用方法
|
|
52
|
+
|
|
53
|
+
### Windows GUI
|
|
54
|
+
|
|
55
|
+
程序运行后会出现一个简洁的界面:
|
|
56
|
+
|
|
57
|
+

|
|
58
|
+
|
|
59
|
+
### 基本使用(适合大多数用户):
|
|
60
|
+
|
|
61
|
+
1. 点击"转PDF"按钮(请确保点击时PowerPoint是打开的)
|
|
62
|
+
2. 选择保存位置并点击"保存",则**当前活跃的PPT页面**会导出为PDF文件并自动裁剪白边
|
|
63
|
+
3. 默认保存路径为当前活跃PPT文件所在目录
|
|
64
|
+
|
|
65
|
+
### 高级设置(需要精细控制时):
|
|
66
|
+
|
|
67
|
+
点击"▼ 显示高级设置"展开详细参数控制:
|
|
68
|
+
|
|
69
|
+
#### 快速设置预设:
|
|
70
|
+
- **紧密裁剪**: 完全去除白边
|
|
71
|
+
- **小白边**: 保留约1mm白边
|
|
72
|
+
- **中白边**: 保留约2mm白边
|
|
73
|
+
- **保留原边距**: 保留10%的原始边距
|
|
74
|
+
|
|
75
|
+
#### 详细参数设置:
|
|
76
|
+
|
|
77
|
+
1. **保留原始边距(%)**: 设置保留原PDF边距的百分比
|
|
78
|
+
- 0% = 完全去除边距(紧密裁剪)
|
|
79
|
+
- 10% = 保留10%的原始边距
|
|
80
|
+
- 适合对有一定边距的PDF进行微调
|
|
81
|
+
|
|
82
|
+
2. **额外白边(bp)**: 在裁剪后额外增加的白边大小
|
|
83
|
+
- 单位为 bp (big points),1bp ≈ 0.35mm
|
|
84
|
+
- 适合需要为图片添加统一白边的场景
|
|
85
|
+
|
|
86
|
+
3. **检测阈值**: 背景检测的阈值设置 (0-255)
|
|
87
|
+
- 默认值191适合大多数情况
|
|
88
|
+
- 值越小检测越严格,适合灰色背景
|
|
89
|
+
- 值越大检测越宽松
|
|
90
|
+
|
|
91
|
+
4. **裁剪选项**:
|
|
92
|
+
- **统一裁剪**: 所有页面使用相同的裁剪量
|
|
93
|
+
- **统一页面大小**: 所有页面设为相同尺寸
|
|
94
|
+
|
|
95
|
+
### CLI
|
|
96
|
+
|
|
97
|
+
CLI 适用于 Linux、macOS、Windows,不依赖 PowerPoint。
|
|
98
|
+
程序会自动检测本机候选后端。
|
|
99
|
+
当前已实现的自动导出后端是:
|
|
100
|
+
|
|
101
|
+
- `LibreOffice`: Windows / Linux / macOS
|
|
102
|
+
- `PowerPoint`: Windows / macOS
|
|
103
|
+
- `WPS`: Windows
|
|
104
|
+
|
|
105
|
+
`--list-backends` 会尽量按当前平台列出已检测到的候选程序,即使该平台暂时还没有实现对应的自动导出驱动。
|
|
106
|
+
在 `auto` 模式下,默认优先级是 `LibreOffice > WPS > PowerPoint`。
|
|
107
|
+
|
|
108
|
+
基本示例:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
ppt2fig ./demo.pptx --pages 3
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
导出多个页码:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
ppt2fig ./demo.pptx --pages 1,3,5-7 -o ./figure.pdf
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
关闭裁剪:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
ppt2fig ./demo.pptx --pages 2 --no-crop
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
指定 LibreOffice 可执行文件:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
ppt2fig ./demo.pptx --pages 4 --office-bin /usr/bin/soffice
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
强制使用 PowerPoint 后端:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
ppt2fig ./demo.pptx --pages 2 --backend powerpoint
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
强制使用 WPS 后端:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
ppt2fig ./demo.pptx --pages 2 --backend wps
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
使用 PowerPoint 的打印质量导出:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
ppt2fig ./demo.pptx --pages 2 --backend powerpoint --powerpoint-intent print
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
查看当前机器检测到的候选后端:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
ppt2fig --list-backends
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
常用参数:
|
|
157
|
+
|
|
158
|
+
- `--pages`: 必填,支持 `1,3,5-7`
|
|
159
|
+
- `--output`: 输出 PDF 路径
|
|
160
|
+
- `--office-bin`: 指定 `soffice` 或 `libreoffice`
|
|
161
|
+
- `--backend`: 选择 `auto`、`libreoffice`、`powerpoint` 或 `wps`
|
|
162
|
+
- `--powerpoint-intent`: PowerPoint 后端使用 `print` 或 `screen`
|
|
163
|
+
- `--bitmap-missing-fonts`: 字体无法嵌入时将文字转为位图
|
|
164
|
+
- `--list-backends`: 查看当前检测到的候选后端
|
|
165
|
+
- `--no-crop`: 不裁剪白边
|
|
166
|
+
- `--percent-retain`: 保留原始边距百分比
|
|
167
|
+
- `--margin-size`: 额外白边,单位 bp
|
|
168
|
+
- `--threshold`: 背景检测阈值
|
|
169
|
+
- `--no-uniform`: 禁用统一裁剪
|
|
170
|
+
- `--no-same-size`: 禁用统一页面大小
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
## 系统要求
|
|
174
|
+
|
|
175
|
+
- GUI:
|
|
176
|
+
- Windows
|
|
177
|
+
- Microsoft PowerPoint
|
|
178
|
+
- CLI:
|
|
179
|
+
- Windows / Linux / macOS
|
|
180
|
+
- 推荐 LibreOffice
|
|
181
|
+
- Python 3.8+
|
|
182
|
+
|
|
183
|
+
## 依赖项(安装时自动安装)
|
|
184
|
+
|
|
185
|
+
- comtypes: Windows GUI 下用于与PowerPoint交互
|
|
186
|
+
- pdfCropMargins: 裁剪PDF白边
|
|
187
|
+
- pypdf: 从导出的整份 PDF 中提取指定页
|
|
188
|
+
- tkinter: Python 自带,仅 GUI 使用
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
## 注意事项
|
|
192
|
+
|
|
193
|
+
- GUI 使用前请确保已经打开 PowerPoint
|
|
194
|
+
- GUI 依赖当前活动演示文稿
|
|
195
|
+
- CLI 会先自动检测候选后端;不同平台上的自动导出支持范围不同
|
|
196
|
+
- `--list-backends` 中的 `detected` 表示发现了候选程序,但当前平台未必已经实现自动导出
|
|
197
|
+
- CLI 当前通过导出整份 PDF 后再抽取指定页,因此页码以导出后的 PDF 页序为准
|
|
198
|
+
- 如果系统里没有可用的 LibreOffice 兼容后端,请安装 LibreOffice 或用 `--office-bin` 显式指定路径
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
## 编译指南
|
|
202
|
+
|
|
203
|
+
1. 下载源码
|
|
204
|
+
2. 创建一个环境,只安装本项目依赖和pyinstaller
|
|
205
|
+
3. 参考[配置upx](https://blog.csdn.net/JiuShu110/article/details/132625538)配置upx,用于压缩exe文件
|
|
206
|
+
4. 编译
|
|
207
|
+
```cmd
|
|
208
|
+
pyinstaller -F -w -n ppt2fig --optimize=2 ppt2fig/main.py
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 许可证
|
|
212
|
+
|
|
213
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from .core import detect_backends, export_selected_pages, parse_page_range
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def build_parser():
|
|
8
|
+
parser = argparse.ArgumentParser(
|
|
9
|
+
prog="ppt2fig",
|
|
10
|
+
description="将指定 PPTX 的指定页导出为 PDF,并可选自动裁剪白边。",
|
|
11
|
+
)
|
|
12
|
+
parser.add_argument("pptx", nargs="?", help="输入的 PPTX 文件路径")
|
|
13
|
+
parser.add_argument(
|
|
14
|
+
"-p",
|
|
15
|
+
"--pages",
|
|
16
|
+
help="要导出的页码,支持 1,3,5-7 这种格式,页码从 1 开始",
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-o",
|
|
20
|
+
"--output",
|
|
21
|
+
help="输出 PDF 路径,默认在输入文件同目录下生成",
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"--office-bin",
|
|
25
|
+
help="手动指定导出后端可执行文件路径,例如 soffice 或 libreoffice",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--backend",
|
|
29
|
+
choices=["auto", "libreoffice", "powerpoint", "wps"],
|
|
30
|
+
default="auto",
|
|
31
|
+
help="选择导出后端,默认 auto",
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"--list-backends",
|
|
35
|
+
action="store_true",
|
|
36
|
+
help="列出当前系统检测到的候选后端并退出",
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"--powerpoint-intent",
|
|
40
|
+
choices=["print", "screen"],
|
|
41
|
+
default="print",
|
|
42
|
+
help="PowerPoint 后端的导出意图,默认 print",
|
|
43
|
+
)
|
|
44
|
+
parser.add_argument(
|
|
45
|
+
"--bitmap-missing-fonts",
|
|
46
|
+
action="store_true",
|
|
47
|
+
help="PowerPoint 后端在字体无法嵌入时将文字位图化",
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument("--no-crop", action="store_true", help="导出后不裁剪白边")
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--percent-retain",
|
|
52
|
+
type=float,
|
|
53
|
+
default=0.0,
|
|
54
|
+
help="保留原始边距的百分比,默认 0",
|
|
55
|
+
)
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--margin-size",
|
|
58
|
+
type=float,
|
|
59
|
+
default=0.0,
|
|
60
|
+
help="裁剪后额外增加的白边,单位 bp,默认 0",
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--threshold",
|
|
64
|
+
type=int,
|
|
65
|
+
default=191,
|
|
66
|
+
help="背景检测阈值,默认 191",
|
|
67
|
+
)
|
|
68
|
+
parser.add_argument(
|
|
69
|
+
"--no-uniform",
|
|
70
|
+
action="store_true",
|
|
71
|
+
help="禁用统一裁剪",
|
|
72
|
+
)
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"--no-same-size",
|
|
75
|
+
action="store_true",
|
|
76
|
+
help="禁用统一页面大小",
|
|
77
|
+
)
|
|
78
|
+
return parser
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def default_output_path(pptx_path, pages):
|
|
82
|
+
source = Path(pptx_path).resolve()
|
|
83
|
+
page_label = "_".join(str(page) for page in pages)
|
|
84
|
+
return source.with_name(f"{source.stem}.pages_{page_label}.pdf")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def main(argv=None):
|
|
88
|
+
parser = build_parser()
|
|
89
|
+
args = parser.parse_args(argv)
|
|
90
|
+
|
|
91
|
+
if args.list_backends:
|
|
92
|
+
backends = detect_backends(explicit_path=args.office_bin)
|
|
93
|
+
if not backends:
|
|
94
|
+
print("未检测到任何候选后端")
|
|
95
|
+
return
|
|
96
|
+
for backend in backends:
|
|
97
|
+
status = "supported" if backend.supported else "detected"
|
|
98
|
+
suffix = f" ({backend.detail})" if backend.detail else ""
|
|
99
|
+
print(f"{backend.name}\t{status}\t{backend.path}{suffix}")
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
if not args.pptx:
|
|
103
|
+
parser.error("缺少输入文件 pptx")
|
|
104
|
+
if not args.pages:
|
|
105
|
+
parser.error("missing required argument: -p/--pages")
|
|
106
|
+
|
|
107
|
+
pages = parse_page_range(args.pages)
|
|
108
|
+
source = Path(args.pptx).resolve()
|
|
109
|
+
if not source.exists():
|
|
110
|
+
parser.error(f"输入文件不存在: {source}")
|
|
111
|
+
if source.suffix.lower() not in {".pptx", ".ppt", ".odp"}:
|
|
112
|
+
parser.error("输入文件必须是 .pptx、.ppt 或 .odp")
|
|
113
|
+
|
|
114
|
+
output = Path(args.output).resolve() if args.output else default_output_path(source, pages)
|
|
115
|
+
export_selected_pages(
|
|
116
|
+
source,
|
|
117
|
+
output,
|
|
118
|
+
pages,
|
|
119
|
+
backend=args.backend,
|
|
120
|
+
office_bin=args.office_bin,
|
|
121
|
+
powerpoint_intent=args.powerpoint_intent,
|
|
122
|
+
bitmap_missing_fonts=args.bitmap_missing_fonts,
|
|
123
|
+
no_crop=args.no_crop,
|
|
124
|
+
percent_retain=args.percent_retain,
|
|
125
|
+
margin_size=args.margin_size,
|
|
126
|
+
use_uniform=not args.no_uniform,
|
|
127
|
+
use_same_size=not args.no_same_size,
|
|
128
|
+
threshold=args.threshold,
|
|
129
|
+
)
|
|
130
|
+
print(output)
|