从 0.23.0 起,fsys.openXml.pptx.editor 可以将本页已有的空图片占位符填为嵌入式 PNG/JPEG,仍保留它的框、形状 ID 和占位符身份。要给普通图片换文件,请使用 replaceImage;若要在版式上新增占位符或调整裁剪,不是本接口的范围。
使用 pptx.read(...,{includeStructure=true}) 的 pages[].placeholders 或会话的 listPlaceholders(page):空框是 kind="sp"、placeholder.type="pic",填完后 kind="pic",占位符的 type/index 不变。不要把默认 obj 内容框当作图片框,也不要把形状 ID 当占位符索引。
示例假定 /picture-template.pptx 的第 1 页已有 pic/1;图片选右边缘,跨页批填时可先 copySlide 并使用返回的 index:
import fsys.openXml.pptx;
import fsys.openXml.pptx.editor;
var pptx=fsys.openXml.pptx;
var doc,err=pptx.editor.open("/picture-template.pptx");
if(!doc) return null,err;
var pic,err=doc.setPlaceholderImage(1,{type="pic";index=1},
{path="/picture-input.png";imageAlignX=1});
if(!pic){doc.close();return null,err;}
var path,err=doc.save("/picture-filled.pptx");
doc.close();
if(!path) return null,err;
var report,err=pptx.verify(path);
if(!report) return null,err;
if(!report.ok || !report.complete) return null,"另存文件未通过结构校验",report;
return {path=path;picture=pic};
doc.setPlaceholderImage(page,target,image):page 是当前 1-based 页号。target 为数值形状 ID、唯一且区分大小写的名称,或 {type="pic";index=N}(有且仅有一个同类时可省略 index;缺省索引为 0)。可直接传有效的 shape.placeholder。成功返回 {id,name,placeholder,partName,relationshipId,geometrySource};失败 null,err。image 传 {path=本地路径} 或 {data=PNG/JPEG字节串或buffer},二选一。拒绝 URL、UNC 和设备路径。图片以原字节嵌入;每次填充新增独立媒体部件,不重写其他对象的图片。fit 默认 cover,等比铺满原框,只裁源图;imageAlignX/Y 为 0..1,默认 0.5 居中,0/1 分别取左/右或上/下对齐。fit="stretch" 不裁剪,可能变形,不接收锚点。不支持 contain、手动 crop 或 imageOpacity。geometrySource 表示所用宽高来自 slide 或 layout;reader 的 geometry 仍只报告保存的直接变换。部分变换、非矩形、只在母版/版式出现的占位符、组内或兼容分支,都不强行处理。verify 是结构检查,不替代目标应用的视觉或放映验收。