aardio 文档

填充已有的空图片占位符

从 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};

参数和边界

Markdown 格式