在汇报演示前,PPT 的宽高比往往需要统一,有的会议屏是 4:3 标准比例,有的投影仪是 16:9 宽屏。这就需要版式双向转换,而且转换过程中需要自动调整文字大小与图片位置,确保内容正常显示、无文字溢出或图片错位。本文介绍如何使用 Spire.Agent.Office PowerPoint AI 能力,将 PPT 演示文稿在 4:3 标准比例与 16:9 宽屏比例之间批量转换。
对比传统SDK API处理
| 传统 Spire.Office for .NET API | Spire.Agent.Office 处理 | |
|---|---|---|
| 驱动方式 | 硬编码的API调用 | 1条自然语言指令 |
| 需求变更 | 需求变更需要修改代码并重新部署 | 需求变化时只需修改指令文本,无需重新编译代码 |
有关产品安装和 SpireToken 配置,请参考 在 .NET 项目中集成 Spire.Agent.Office。以下示例默认已安装 Spire.Agent.Office 并完成 SpireToken 配置。
4:3 标准转 16:9 宽屏
所有幻灯片的内容结构、主题与配色保持不变,文字大小与图片位置自动适配宽屏画布,多页 PPT 一次转换完成。
using Spire.Agent.Office.AI;
using Spire.Agent.Office.Extensions;
using Spire.Presentation;
// PowerPoint AI处理配置
string inputPath = @"ratio_43.pptx";
string savePath = @"output.pptx";
// SpireToken Key
string key = "**************************";
string instruction = "读取输入PPT演示文稿,将其从 4:3 标准比例批量转换为 16:9 宽屏比例";
AIResult result = ExecuteDemoPpt(instruction, inputPath, savePath, key);
// 执行PowerPoint文档AI处理
static AIResult ExecuteDemoPpt(string instruction, string inputPath, string savePath, string key)
{
// 创建AIOptions选项配置对象
AIOptions options = new AIOptions();
options.SpireToken = key;
// 使用Presentation对象处理PowerPoint文档
using (Presentation ppt = new Presentation())
{
// 从文件加载PPT
if (!string.IsNullOrEmpty(inputPath) && File.Exists(inputPath))
{
ppt.LoadFromFile(inputPath);
}
// 创建AI文档处理器
AIDocumentProcessor processor = ppt.AI(options);
// 执行AI指令
return processor.ExecuteInstruction(ppt, instruction, savePath);
}
}
原 4:3 标准 PPT
转换后的 16:9 宽屏 PPT

16:9 宽屏转 4:3 标准
using Spire.Agent.Office.AI;
using Spire.Agent.Office.Extensions;
using Spire.Presentation;
// PowerPoint AI处理配置
string inputPath = @"ratio_169.pptx";
string savePath = @"output.pptx";
// SpireToken Key
string key = "**************************";
string instruction ="读取输入PPT演示文稿,将其从 16:9 宽屏比例批量转换为 4:3 标准比例";
// 调用PowerPoint文档处理函数
AIResult result = ExecuteDemoPpt(instruction, inputPath, savePath, key);
// 执行PowerPoint文档AI处理(与上文相同的辅助函数)
static AIResult ExecuteDemoPpt(string instruction, string inputPath, string savePath, string key)
{
AIOptions options = new AIOptions();
options.SpireToken = key;
using (Presentation ppt = new Presentation())
{
if (!string.IsNullOrEmpty(inputPath) && File.Exists(inputPath))
{
ppt.LoadFromFile(inputPath);
}
AIDocumentProcessor processor = ppt.AI(options);
return processor.ExecuteInstruction(ppt, instruction, savePath);
}
}
原 16:9 宽屏 PPT
转换后的 4:3 标准 PPT

常见问题
结果文档页丢失
原因:如果原文档页数较多,AI处理分析相对会耗时些,AIOptions.TimeoutMs超时设置默认为5分钟,如果超出,AI分析会中断。
解决:设置AIOptions.TimeoutMs足够时间,例如:
AIOptions options = new AIOptions();
options.TimeoutMs = 1000000;
获取SpireToken Key
- 联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。 或访问 https://www.e-iceblue.com/TemLicense.html 获得试用/商业 API 密钥
在代码中配置:
AIOptions options = new AIOptions();
options.SpireToken = key;







