跳到主要内容

签章/图片插入

功能说明

与业务系统集成后,可在文档中指定位置插入签章/图片。

注意事项

  1. 以下以插入浮动图片为例,若要插入行内图片,使用 InlineShapes.addPicture API。
  2. addPicture 仅支持传入 File 对象,需要提前将图片资源(比如 base64)转成 File 对象。

代码示例

示例 1:在当前选区插入浮动图片

async function insertPicture(file, width, height, wrapType) {
const shape = await app.ActiveDocument.Shapes.addPicture(
file,
undefined,
undefined,
width,
height,
undefined,
wrapType
);
}

示例 2:在指定书签位置插入浮动图片

async function insertPicture(file, width, height, wrapType) {
const bm = await app.ActiveDocument.Bookmarks.item('bm1');
const range = await bm.range;
const shape = await app.ActiveDocument.Shapes.addPicture(
file,
undefined,
undefined,
width,
height,
range,
wrapType
);
}

示例 3:在指定可编辑区域位置插入浮动图片

async function insertPicture(file, width, height, wrapType) {
const pm = await app.ActiveDocument.PermMarks.item('pm1');
const range = await pm.range;
const shape = await app.ActiveDocument.Shapes.addPicture(
file,
undefined,
undefined,
width,
height,
range,
wrapType
);
}