固定在 Paragraph
中的固定位置圖片。與 InlineImage
不同,PositionedImage
並非 Element
。沒有父項或同層級 Element
。而是錨定為 Paragraph
或 ListItem
,並透過與該錨點的偏移放置。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 網域可能暫時適用更嚴格的配額。
參數
名稱 | 類型 | 說明 |
---|---|---|
contentType | String | 要轉換的 MIME 類型。對多數 blob 而言,'application/pdf' 是唯一的有效選項。如果是 BMP、GIF、JPEG 或 PNG 格式的圖片,'image/bmp' 、'image/gif' 、'image/jpeg' 或 'image/png' 中的任一個也是有效的格式。 |
回攻員
Blob
:資料做為 blob。
getBlob()
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()
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)
設定圖片的高度 (以像素為單位)。
參數
名稱 | 類型 | 說明 |
---|---|---|
height | Integer | 圖片的高度 (以像素為單位) |
回攻員
PositionedImage
:目前的物件
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLayout(layout)
設定圖片的配置方式。
參數
名稱 | 類型 | 說明 |
---|---|---|
layout | PositionedLayout | 列舉代表版面配置模式的列舉 |
回攻員
PositionedImage
:這個物件用於鏈結
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLeftOffset(offset)
設定圖片從段落左側的偏移值。
參數
名稱 | 類型 | 說明 |
---|---|---|
offset | Number | 距離段落左側偏移 |
回攻員
PositionedImage
:這個物件用於鏈結
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTopOffset(offset)
設定圖片從段落頂端開始的偏移值。
參數
名稱 | 類型 | 說明 |
---|---|---|
offset | Number | 與段落頂端之間的偏移 |
回攻員
PositionedImage
:這個物件用於鏈結
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setWidth(width)
設定圖片的寬度 (以像素為單位)。
參數
名稱 | 類型 | 說明 |
---|---|---|
width | Integer | 圖片的寬度 (以像素為單位) |
回攻員
PositionedImage
:目前的物件
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents