Sisipkan gambar inline

Anda dapat menyisipkan gambar ke dalam dokumen menggunakan metode InsertInlineImageRequest. Anda dapat menggunakan kolom objectSize secara opsional untuk mengubah ukuran gambar.

Java

List<Request> requests = new ArrayList<>();
requests.add(new Request().setInsertInlineImage(new InsertInlineImageRequest()
        .setUri("https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png")
        .setLocation(new Location().setIndex(1).setTabId(TAB_ID))
        .setObjectSize(new Size()
                .setHeight(new Dimension()
                        .setMagnitude(50.0)
                        .setUnit("PT"))
                .setWidth(new Dimension()
                        .setMagnitude(50.0)
                        .setUnit("PT")))));

BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest().setRequests(requests);
BatchUpdateDocumentResponse response = docsService.documents()
        .batchUpdate(DOCUMENT_ID, body).execute();

PHP

$requests = array();
$requests[] = new Google_Service_Docs_Request(array(
    'insertInlineImage' => array(
        'uri' => 'https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png',
        'location' => array(
            'index' => 1,
            'tabId' => TAB_ID,
        ),
        'objectSize' => array(
            'height' => array(
                'magnitude' => 50,
                'unit' => 'PT',
            ),
            'width' => array(
                'magnitude' => 50,
                'unit' => 'PT',
            ),
        )
    )
));

// Execute the requests.
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
    'requests' => $requests
));
$response =
    $docsService->documents->batchUpdate(DOCUMENT_ID, $batchUpdateRequest);

Python

requests = [{
    'insertInlineImage': {
        'location': {
            'index': 1,
            'tabId': TAB_ID
        },
        'uri':
            'https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png',
        'objectSize': {
            'height': {
                'magnitude': 50,
                'unit': 'PT'
            },
            'width': {
                'magnitude': 50,
                'unit': 'PT'
            }
        }
    }
}]

# Execute the request.
body = {'requests': requests}
response = service.documents().batchUpdate(
    documentId=document_id, body=body).execute()
insert_inline_image_response = response.get('replies')[0].get(
    'insertInlineImage')
print('Inserted image with object ID: {0}'.format(
    insert_inline_image_response.get('objectId')))

Metode ini menyisipkan gambar sebagai ParagraphElement baru dengan InlineObjectElement dengan panjang 1, dengan startIndex adalah lokasi permintaan.