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