如何通过PHP代码将文本和图像内容插入到Google文档中

问题描述 投票:0回答:1

我正在使用google API的lib:composer需要google / apiclient:^ 2.0来自:https://developers.google.com/docs/api/quickstart/php

任何人都可以帮我如何创建新的谷歌文档文件,然后通过API插入文本和图像?

php google-docs-api
1个回答
1
投票

有一个可用的documentation用于使用InsertInlineImageRequest方法将图像插入到文档中。

$requests = array();
$requests[] = new Google_Service_Docs_Request(array(
    'insertInlineImage' => array(
        'uri' => 'https://www.gstatic.com/images/branding/product/1x/docs_64dp.png',
        'location' => array(
            'index' => 1,
        ),
        '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);

该方法将图像作为新的ParagraphElement插入,长度为1的InlineObjectElement,其中startIndex是请求的位置。您还可以选择指定调整图像大小的大小。

© www.soinside.com 2019 - 2024. All rights reserved.