title: 导出、压缩与 PPT 拼图业务逻辑 date: 2026-08-27 tags:

  • AiPPT
  • 导出
  • PPT压缩
  • PPT拼图 status: active

导出、压缩与 PPT 拼图业务逻辑

快速认识

三条状态结论:

  • 压缩只在Windows PowerPoint实现;macOS未找到Native压缩处理器,WPS Linux的dispatcher未注册CompressPresentation,Windows WPS宿主返回版本不支持。
  • WPS导出的PDF是图片型PDF:代码先导出JPEG再写入PDF 1.4结构,文字不可选,不支持PDF密码。
  • ExportLongImage输出逐页图片目录:每页导出一张图片放进同名目录,不是把所有页面拼成一张纵向长图。

三项业务共用离线Web页面和TypeScript协议,文件生成由各平台实现。

业务页面输出
导出pages/offline/exportPDF、图片、PPTX、视频
压缩pages/offline/compress-presentation清理后的PPTX
PPT拼图pages/offline/puzzle-picsPNG或JPEG

平台能力总览:

能力WindowsmacOSWPS Linux
PDF原生PDFNative桥图片型PDF
逐页图片已实现已实现已实现
新PPT已实现已实现已实现
图片集PPTOpen XML背景Native桥AddPicture铺满
视频CreateVideoNative桥取决于WPS CreateVideo
压缩已实现未实现未实现
拼图GDI+Swift图形APICanvas

1. 导出页面

导出聚合页按菜单加载五个面板:

ExportLongImage
ExportVideo
ExportImageSet
ExportPPT
ExportPDF

入口:

pages/offline/export/App.tsx
pages/offline/export/hooks/useExportMenus.tsx

视频能力不可用时,菜单不显示视频项。

2. 导出协议

方法主要参数输出
ExportPdf.Exportslides、filePath、openAfterExportPDF
ExportLongImage.Exportslides、width、filePath逐页图片目录
ExportSlidesToPresentation.Exportslides、filePath、encryptInfoPPTX
ExportSlidesToPresentation.ExportImageSetslides、filePath图片型PPTX
ExportVideo.Export分辨率、帧率、时长、质量MP4

协议代码:

common/client-communication/ExportPdf.ts
common/client-communication/ExportLongImage.ts
common/client-communication/ExportSlidesToPresentation.ts
common/client-communication/ExportVideo.ts

3. Windows导出

Native实现:

aippt_windows_addin/src/AiPPTAddin/WebviewJsCallback/
├── ExportPdf/
├── ExportLongImage/
├── ExportSlidesToPresentation/
└── ExportVideo/

PDF

保存临时副本
→ 删除未选Slide
→ ExportAsFixedFormat
→ 关闭副本
→ 删除临时文件

新PPT

保存临时副本
→ 删除未选Slide
→ SaveCopyAs PPTX
→ 设置Password/WritePassword

图片集PPT

逐页导出PNG,再用Open XML创建PPTX,把图片作为整页背景。Office 2010下导出宽度限制为3072。

视频

调用:

Presentation.CreateVideo
→ 每100ms检查CreateVideoStatus
→ Done或Failed

4. macOS导出

代码:

AiPPTAddin/Native/
├── ExportPdf/
├── ExportLongImage/
├── ExportSlidesToPresentation/
├── ExportVideo/
└── JoinImage/

PDF、PPT和视频通过CallbackType转发到dylib/VBA/AppleScript桥。长图和拼图在Swift中处理。

5. WPS导出

WPS Linux实现集中在:

wps-dispatcher.ts

PDF

WPS没有使用原生PDF接口。代码先导出JPEG,再写入PDF 1.4结构,结果是图片型PDF:

  • 文字不可选;
  • 不支持PDF密码;
  • 体积和清晰度取决于图片宽度。

新PPT

Presentations.Add
→ 复制选中Slide
→ SaveAs或SaveCopyAs

图片集PPT

新建PPT后使用AddPicture铺满页面。Windows端使用Open XML背景填充,两端文件结构不同。

视频

只有目标WPS提供CreateVideo时才能执行。代码还会检查输出文件是否出现,并设置10分钟超时。

6. PPT压缩

页面:

pages/offline/compress-presentation

压缩前先调用:

CompressPresentation.RefreshCount

统计六类内容:

未使用版式
动画
版外内容
不可见内容
备注
批注

执行参数:

filePath
compressImage
quality
compressPresentationKinds
openAfterExport

Windows实现

WebviewJsCallback/CompressPresentation/

处理顺序:

  1. 保存PPT副本;
  2. 用COM统计内容;
  3. 用Open XML删除指定内容;
  4. 用pingo压缩图片;
  5. 返回压缩前后文件大小。

删除器:

RemoveUnusedLayout
RemoveAnimation
RemoveOffSlideContent
RemoveHiddenPart
RemoveNote
RemoveComment

平台状态

平台状态
Windows PowerPoint已实现
macOS PowerPoint未找到Native压缩处理器
WPS Linuxdispatcher未注册CompressPresentation
Windows WPS宿主返回版本不支持

压缩入口不应在未实现平台上显示为可用。

7. PPT拼图

页面:

pages/offline/puzzle-pics

默认配置:

输出宽度1920
每行1张
内外边距4
背景色#e4e2e2
PNG
关闭水印

协议:

方法用途
JoinImage.ExportThumbnails导出Slide缩略图
JoinImage.GetPatternWatermark生成图案水印
JoinImage.Join拼接并写文件

布局支持:

  • 每行数量;
  • 内外边距;
  • 页头和页脚;
  • 空位补白;
  • 背景色;
  • 文字或图片水印;
  • PNG/JPEG。

Windows

Slide.Export
→ GDI+ Bitmap/Graphics
→ pingo压缩
→ 写入目标图片

macOS

PowerPoint导出图片
→ Swift NSBitmapImageRep
→ 水印和网格合成

WPS Linux

WPS导出Slide
→ HTML Canvas
→ 绘制背景、网格和水印
→ toDataURL
→ WPS FileSystem写入

8. 错误和取消

导出页面负责:

  • 校验文件名和输出目录;
  • 选择Slide;
  • 展示进度;
  • 取消任务;
  • 导出后打开文件或目录。

Native/WPS层负责:

  • 判断API是否存在;
  • 清理临时文件;
  • 返回明确错误;
  • 不支持时拒绝执行。

9. 代码位置

pages/offline/export/
pages/offline/compress-presentation/
pages/offline/puzzle-pics/
common/client-communication/Export*.ts
common/client-communication/CompressPresentation.ts
common/client-communication/JoinImage.ts
common/client-communication/wps-dispatcher.ts

相关文档: