How can I control the placement of images when using a Laravel implementation with the Google Docs API? Below is a revised PHP sample that inserts inline images without using unsupported offset properties.
public function generateDocWithPhotos(Request $req)
{
$apiClient = new Google_Client();
$apiClient->setAuthConfig('../config/google_service_account.json');
$apiClient->setApplicationName('Docs API Integration');
$apiClient->setScopes([Google_Service_Docs::DOCUMENTS, Google_Service_Drive::DRIVE]);
$docsService = new Google_Service_Docs($apiClient);
$documentData = new Google_Service_Docs_Document(['title' => 'New Document']);
$createdDoc = $docsService->documents->create($documentData);
$docKey = $createdDoc->documentId;
$operations = [];
$operations[] = new Google_Service_Docs_Request([
'insertInlineImage' => [
'uri' => 'https://example.com/sample-image.png',
'location' => ['index' => 1],
'objectSize' => [
'height' => ['magnitude' => 40, 'unit' => 'PT'],
'width' => ['magnitude' => 40, 'unit' => 'PT']
]
]
]);
$batchRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(['requests' => $operations]);
$docsService->documents->batchUpdate($docKey, $batchRequest);
return response()->json(['docId' => $docKey]);
}