PPT转PDF_图片
更新时间:2026-06-12
简介
PPT 转换处理器,支持 PPT/PPTX 转 PDF 及每页图片
功能描述
- 支持将 PPT/PPTX 文档转换为 PDF 文件
- 支持将 PPT/PPTX 转换为按页拆分的 PNG 图片
- 自动处理本地路径与远程路径(BOS/HTTP 等)的下载与上传
- 提供转换超时控制与基础失败兜底
- 批量将演示文稿转换为用于预览或归档的 PDF
- 将演示文稿转换为逐页图片用于在线展示或内容审核
- 依赖本机已安装 LibreOffice(soffice 命令)
- 若未安装 pdf2image,将自动回退到系统的 pdftoppm 工具进行图片转换
- 当前支持生成 PNG/JPG 图片格式
算子参数
输入
| 输入 | 含义 |
|---|---|
| files | 输入文件路径数组,支持 bos、http(s) 以及本地路径。 |
输出
| 输出 | 含义 |
|---|---|
| result | 输出处理后的路径字符串数组,与输入一一对应;单条失败时对应位置返回空字符串。 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| target_format | str | 必填 | 目标格式,"pdf" 表示仅生成 PDF,"images" 表示生成每页图片并返回图片文件夹路径。 |
| output_dir | str | 必填 | 输出路径,必须提供,可以是本地路径或 BOS 路径。 |
| convert_time_out | int | 600 | 转换超时时间(秒),用于控制 soffice / pdftoppm 执行时间。 |
| image_dpi | int | 200 | 图片转换时的 DPI 分辨率,仅在 target_format="images" 时生效。 |
| image_format | str | 'png' | 图片格式,当前支持 "png" 、"jpg"、"jpeg",仅在 target_format="images" 时生效。 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.doc.ppt_convert import PPTConvert
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18 # TODO: 根据实际场景准备样本数据
19 samples = {"files": [...]}
20 ds = daft.from_pydict(samples)
21 constructor_kwargs = {
22 "convert_time_out": 600,
23 "image_dpi": 200,
24 "image_format": 'png',
25 }
26 ds = ds.with_column(
27 "result",
28 aihc_udf(
29 PPTConvert,
30 construct_args=constructor_kwargs,
31 num_cpus=1,
32 concurrency=4,
33 batch_size=8,
34 )(col("files")),
35 )
36 ds.show()
评价此篇文章
