Class PositionedImage

PositionedImage

锚定到 Paragraph 的固定位置图片。与 InlineImage 不同,PositionedImage 不是 Element。它没有父级或同级元素Element。而是锚定到 ParagraphListItem,并通过相对于该锚点的偏移量来放置。PositionedImage 具有可用于引用它的 ID。

var body = DocumentApp.getActiveDocument().getBody();

// Append a new paragraph.
var paragraph = body.appendParagraph("New paragraph to anchor the image to.");

// Get an image in Drive from its ID.
var image = DriveApp.getFileById('ENTER_IMAGE_FILE_ID_HERE').getBlob();

// Add the PositionedImage with offsets (in points).
var posImage = paragraph.addPositionedImage(image)
    .setTopOffset(60)
    .setLeftOffset(40);

方法

方法返回类型简介
getAs(contentType)Blob返回此对象内的数据,并将其作为 blob 转换为指定内容类型。
getBlob()Blob以 blob 的形式返回此对象内的数据。
getHeight()Integer检索图片的高度(以像素为单位)。
getId()String获取图片的 ID。
getLayout()PositionedLayout获取表示图像布局方式的枚举值。
getLeftOffset()Number获取图片相对于段落左侧的偏移量(以点为单位)。
getParagraph()Paragraph获取图片锚定到的 Paragraph
getTopOffset()Number获取图片相对于段落顶部的偏移量(以点为单位)。
getWidth()Integer检索图片的宽度(以像素为单位)。
setHeight(height)PositionedImage设置图片的高度(以像素为单位)。
setLayout(layout)PositionedImage设置图像的布局方式。
setLeftOffset(offset)PositionedImage设置图片相对于段落左侧的偏移量(以点为单位)。
setTopOffset(offset)PositionedImage设置图片相对于段落顶部的偏移量(以点为单位)。
setWidth(width)PositionedImage设置图片的宽度(以像素为单位)。

详细文档

getAs(contentType)

返回此对象内的数据,并将其作为 blob 转换为指定内容类型。此方法会为文件名添加适当的扩展名,例如“myfile.pdf”。不过,它假设最后一个英文句点后面的文件名部分(如果有)是应该替换的现有扩展名。因此,“ShoppingList.12.25.2014”将变为“ShoppingList.12.25.pdf”。

如需查看转化次数的每日配额,请参阅 Google 服务的配额。新创建的 Google Workspace 网域可能会暂时受到更严格的配额限制。

参数

名称类型说明
contentTypeString要转换为的 MIME 类型。对于大多数 blob,'application/pdf' 是唯一有效的选项。对于 BMP、GIF、JPEG 或 PNG 格式的图片,'image/bmp''image/gif''image/jpeg''image/png' 中的任何一个也都有效。

弃踢回攻

Blob - 作为 blob 的数据。


getBlob()

以 blob 的形式返回此对象内的数据。

弃踢回攻

Blob - 作为 blob 的数据。


getHeight()

检索图片的高度(以像素为单位)。

弃踢回攻

Integer - 图片的高度(以像素为单位)

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getId()

获取图片的 ID。

弃踢回攻

String - 映像 ID

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getLayout()

获取表示图像布局方式的枚举值。

弃踢回攻

PositionedLayout - 图片布局

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getLeftOffset()

获取图片相对于段落左侧的偏移量(以点为单位)。

弃踢回攻

Number - 距左侧段落左侧的图片偏移量

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getParagraph()

获取图片锚定到的 Paragraph

弃踢回攻

Paragraph - 父段落

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getTopOffset()

获取图片相对于段落顶部的偏移量(以点为单位)。

弃踢回攻

Number - 距左侧段落顶部的图片偏移量

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getWidth()

检索图片的宽度(以像素为单位)。

弃踢回攻

Integer - 图片的宽度(以像素为单位)

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setHeight(height)

设置图片的高度(以像素为单位)。

参数

名称类型说明
heightInteger图片的高度(以像素为单位)

弃踢回攻

PositionedImage - 当前对象

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setLayout(layout)

设置图像的布局方式。

参数

名称类型说明
layoutPositionedLayout表示布局模式的枚举

弃踢回攻

PositionedImage - 此对象用于实现链接

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setLeftOffset(offset)

设置图片相对于段落左侧的偏移量(以点为单位)。

参数

名称类型说明
offsetNumber距段落左边缘的偏移量

弃踢回攻

PositionedImage - 此对象用于实现链接

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setTopOffset(offset)

设置图片相对于段落顶部的偏移量(以点为单位)。

参数

名称类型说明
offsetNumber距段落顶部的偏移量

弃踢回攻

PositionedImage - 此对象用于实现链接

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setWidth(width)

设置图片的宽度(以像素为单位)。

参数

名称类型说明
widthInteger图片的宽度(以像素为单位)

弃踢回攻

PositionedImage - 当前对象

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents