### Installation Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest Install the Google Cloud Document AI client library for PHP using Composer. ```APIDOC ## Installation To begin, install the preferred dependency manager for PHP, Composer. Now install this component: ``` $ composer require google/cloud-document-ai ``` This component supports both REST over HTTP/1.1 and gRPC. In order to take advantage of the benefits offered by gRPC (such as streaming methods) please see our gRPC installation guide. ``` -------------------------------- ### Get Evaluation Example Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest Example of how to retrieve an evaluation using the Document AI client library for PHP. ```APIDOC ## Sample ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\Evaluation; use Google\Cloud\DocumentAI\V1\GetEvaluationRequest; // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetEvaluationRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var Evaluation $response */ $response = $documentProcessorServiceClient->getEvaluation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` ``` -------------------------------- ### Install Google Cloud Document AI using Composer Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest Use Composer to install the Google Cloud Document AI client library for PHP. This command adds the necessary dependency to your project. ```bash $ composer require google/cloud-document-ai ``` -------------------------------- ### Get Document AI Evaluation using PHP Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest This sample demonstrates how to retrieve an evaluation for a Document AI processor using the PHP client library. Ensure you have authenticated your client before making requests. It handles potential API exceptions. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\Evaluation; use Google\Cloud\DocumentAI\V1\GetEvaluationRequest; // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetEvaluationRequest())     ->setName($formattedName); // Call the API and handle any network failures. try {     /** @var Evaluation $response */     $response = $documentProcessorServiceClient->getEvaluation($request);     printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) {     printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` -------------------------------- ### setY Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Vertex Sets the Y coordinate of the vertex, starting from the top of the image. ```APIDOC ## setY ### Description Sets the Y coordinate of the vertex (starts from the top of the image). ### Parameters #### Request Body - **var** (int) - The new Y coordinate value. ### Returns - **$this**: The current instance of the Vertex object for method chaining. ``` -------------------------------- ### getStartIndex Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.TextAnchor.TextSegment Retrieves the starting UTF-8 character index of the text segment within the Document.text. ```APIDOC ## getStartIndex ### Description TextSegment start UTF-8 char index in the Document.text. ### Returns - **Type**: int|string ``` -------------------------------- ### getY Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Vertex Retrieves the Y coordinate of the vertex, starting from the top of the image. ```APIDOC ## getY ### Description Gets the Y coordinate of the vertex (starts from the top of the image). ### Returns - **int**: The Y coordinate. ``` -------------------------------- ### Get Pages Per Shard Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.DocumentOutputConfig.GcsOutputConfig.ShardingConfig Retrieves the number of pages configured for each shard. ```APIDOC ## getPagesPerShard The number of pages per shard. ### Returns - **int** - The number of pages per shard. ``` -------------------------------- ### PageRef Methods Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.PageAnchor.PageRef Provides methods for getting and setting page reference properties. ```APIDOC ## getPage ### Description Gets the required index into the Document.pages element. ### Returns - **Type**: int|string ``` ```APIDOC ## setPage ### Description Sets the required index into the Document.pages element. ### Parameter - **var** (int|string) - The index into the Document.pages element. ### Returns - **Type**: $this ``` ```APIDOC ## getLayoutType ### Description Gets the optional type of the layout element being referenced. ### Returns - **Type**: int - Enum of type LayoutType. ``` ```APIDOC ## setLayoutType ### Description Sets the optional type of the layout element being referenced. ### Parameter - **var** (int) - Enum of type LayoutType. ### Returns - **Type**: $this ``` ```APIDOC ## getLayoutId ### Description Gets the optional, deprecated layout ID. ### Returns - **Type**: string ``` ```APIDOC ## setLayoutId ### Description Sets the optional, deprecated layout ID. ### Parameter - **var** (string) - The layout ID. ### Returns - **Type**: $this ``` ```APIDOC ## getBoundingPoly ### Description Gets the optional bounding polygon of a layout element on the page. ### Returns - **Type**: Google\Cloud\DocumentAI\V1\BoundingPoly|null ``` ```APIDOC ## hasBoundingPoly ### Description Checks if a bounding polygon is set. ``` ```APIDOC ## clearBoundingPoly ### Description Clears the bounding polygon. ``` ```APIDOC ## setBoundingPoly ### Description Sets the bounding polygon of a layout element on the page. ### Parameter - **var** (Google\Cloud\DocumentAI\V1\BoundingPoly) - The bounding polygon. ### Returns - **Type**: $this ``` ```APIDOC ## getConfidence ### Description Gets the optional confidence score of the detected page element. ### Returns - **Type**: float ``` ```APIDOC ## setConfidence ### Description Sets the optional confidence score of the detected page element. ### Parameter - **var** (float) - The confidence score, range `[0, 1]`. ### Returns - **Type**: $this ``` -------------------------------- ### Get Processor Detail Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Use this method to retrieve details about a specific processor. Ensure the processor name is correctly formatted. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\GetProcessorRequest; use Google\Cloud\DocumentAI\V1\Processor; /** * @param string $formattedName The processor resource name. Please see * {@see DocumentProcessorServiceClient::processorName()} for help formatting this field. */ function get_processor_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetProcessorRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var Processor $response */ $response = $documentProcessorServiceClient->getProcessor($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]' ); get_processor_sample($formattedName); } ``` -------------------------------- ### Get List Block Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the list content block associated with this layout block. ```APIDOC ## getListBlock ### Description Block consisting of list content/structure. ### Returns - **Type**: DocumentLayoutBlock\LayoutListBlock|null - **Description**: The list content block, or null if not present. ``` -------------------------------- ### Get Image Block Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the image content block associated with this layout block. ```APIDOC ## getImageBlock ### Description Block consisting of image content. ### Returns - **Type**: DocumentLayoutBlock\LayoutImageBlock|null - **Description**: The image content block, or null if not present. ``` -------------------------------- ### setStartIndex Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.TextAnchor.TextSegment Sets the starting UTF-8 character index for the text segment. Returns the current object for chaining. ```APIDOC ## setStartIndex ### Description TextSegment start UTF-8 char index in the Document.text. ### Parameter - **var** (int|string) - The start index to set. ### Returns - **Type**: $this ``` -------------------------------- ### Get Text Block Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the text content block associated with this layout block. ```APIDOC ## getTextBlock ### Description Block consisting of text content. ### Returns - **Type**: DocumentLayoutBlock\LayoutTextBlock|null - **Description**: The text content block, or null if not present. ``` -------------------------------- ### Get Processor Version Detail Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves details for a specific processor version. Ensure the processor version name is correctly formatted. This method can throw an ApiException on failure. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\GetProcessorVersionRequest; use Google\Cloud\DocumentAI\V1\ProcessorVersion; /** * @param string $formattedName The processor resource name. Please see * {@see DocumentProcessorServiceClient::processorVersionName()} for help formatting this field. */ function get_processor_version_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetProcessorVersionRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var ProcessorVersion $response */ $response = $documentProcessorServiceClient->getProcessorVersion($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorVersionName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]', '[PROCESSOR_VERSION]' ); get_processor_version_sample($formattedName); } ``` -------------------------------- ### Get Processor Type Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves details about a specific processor type using its resource name. ```APIDOC ## getProcessorType ### Description Gets a processor type detail. The async variant is DocumentProcessorServiceClient::getProcessorTypeAsync(). ### Method POST ### Endpoint /v1/projects/{projectId}/locations/{locationId}/processorTypes/{processorTypeId} ### Parameters #### Path Parameters - **processorTypeName** (string) - Required - The name of the processor type to retrieve. #### Request Body - **request** (Google\Cloud\DocumentAI\V1\GetProcessorTypeRequest) - Required - A request to house fields associated with the call. - **callOptions** (array) - Optional - Options for the API call, including retry settings. - **retrySettings** (RetrySettings|array) - Optional - Retry settings to use for this call. ### Response #### Success Response (200) - **processorType** (Google\Cloud\DocumentAI\V1\ProcessorType) - The details of the processor type. ### Request Example ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\GetProcessorTypeRequest; use Google\Cloud\DocumentAI\V1\ProcessorType; /** * @param string $formattedName The processor type resource name. Please see * \Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient::processorTypeName() for help formatting this field. */ function get_processor_type_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetProcessorTypeRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var ProcessorType $response */ $response = $documentProcessorServiceClient->getProcessorType($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorTypeName( '[PROJECT]', '[LOCATION]', '[PROCESSOR_TYPE]' ); get_processor_type_sample($formattedName); } ``` ``` -------------------------------- ### Get Processor Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves the details of a specific processor. This method allows you to fetch information about a processor's configuration and status. ```APIDOC ## getProcessor ### Description Gets a processor detail. ### Method POST ### Endpoint /v1/projects/{projectId}/locations/{locationId}/processors/{processorId} ### Parameters #### Path Parameters - **projectId** (string) - Required - The project ID. - **locationId** (string) - Required - The location ID. - **processorId** (string) - Required - The processor ID. #### Request Body - **request** (`Google\Cloud\DocumentAI\V1\GetProcessorRequest`) - Required - A request to house fields associated with the call. - **callOptions** (`array`) - Optional - Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. ### Request Example ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\GetProcessorRequest; use Google\Cloud\DocumentAI\V1\Processor; /** * @param string $formattedName The processor resource name. Please see * \Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient::processorName() for help formatting this field. */ function get_processor_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetProcessorRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var Processor $response */ $response = $documentProcessorServiceClient->getProcessor($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]' ); get_processor_sample($formattedName); } ``` ### Response #### Success Response (200) - **Type**: `Google\Cloud\DocumentAI\V1\Processor` - **Description**: The processor resource. #### Response Example ```json { "name": "projects/123456789/locations/us/processors/abcdef1234567890", "type": "PROCEDURE_EXTRACTION", "displayName": "My Processor", "state": "ENABLED", "createTime": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### TextSegment Constructor Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.TextAnchor.TextSegment Initializes a new TextSegment object, optionally with provided data. The data can include start and end indices for the text segment. ```APIDOC ## __construct ### Description Constructor. ### Parameters - **data** (array) - Optional. Data for populating the Message object. - **start_index** (int|string) - TextSegment start UTF-8 char index in the Document.text. - **end_index** (int|string) - TextSegment half open end UTF-8 char index in the Document.text. ``` -------------------------------- ### getLocation Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Gets information about a specific location. This method retrieves details about a supported location within the Document AI service. ```APIDOC ## getLocation ### Description Gets information about a location. ### Method `getLocation` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **request** (`Google\Cloud\Location\GetLocationRequest`) - Required - A request to house fields associated with the call. - **callOptions** (`array`) - Optional - Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. ### Returns - **Type**: `Google\Cloud\Location\Location` - **Description**: Information about the location. ``` -------------------------------- ### Deploy Processor Version Sample Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Deploys a processor version. Use this method to make a specific version of a processor available for use. The sample includes error handling for API calls and operation polling. ```php use Google\ApiCore\ApiException;\nuse Google\ApiCore\OperationResponse;\nuse Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient;\nuse Google\Cloud\DocumentAI\V1\DeployProcessorVersionRequest;\nuse Google\Cloud\DocumentAI\V1\DeployProcessorVersionResponse;\nuse Google\Rpc\Status;\n\n/**\n * @param string $formattedName The processor version resource name to be deployed. Please see\n * {@see DocumentProcessorServiceClient::processorVersionName()} for help formatting this field.\n */\nfunction deploy_processor_version_sample(string $formattedName): void\n{\n // Create a client.\n $documentProcessorServiceClient = new DocumentProcessorServiceClient();\n\n // Prepare the request message.\n $request = (new DeployProcessorVersionRequest())\n ->setName($formattedName);\n\n // Call the API and handle any network failures.\n try {\n /** @var OperationResponse $response */\n $response = $documentProcessorServiceClient->deployProcessorVersion($request);\n $response->pollUntilComplete();\n\n if ($response->operationSucceeded()) {\n /** @var DeployProcessorVersionResponse $result */\n $result = $response->getResult();\n printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());\n } else {\n /** @var Status $error */\n $error = $response->getError();\n printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());\n }\n } catch (ApiException $ex) {\n printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());\n }\n} ``` ```php /**\n * Helper to execute the sample.\n *\n * This sample has been automatically generated and should be regarded as a code\n * template only. It will require modifications to work:\n * - It may require correct/in-range values for request initialization.\n * - It may require specifying regional endpoints when creating the service client,\n * please see the apiEndpoint client configuration option for more details.\n */\nfunction callSample(): void\n{\n $formattedName = DocumentProcessorServiceClient::processorVersionName(\n '[PROJECT]',\n '[LOCATION]',\n '[PROCESSOR]',\n '[PROCESSOR_VERSION]'\n );\n\n deploy_processor_version_sample($formattedName);\n} ``` -------------------------------- ### Get Location Information Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves information about a specific location using the Document AI client. Ensure correct request values and consider regional endpoints for client creation. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function get_location_sample(): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = new GetLocationRequest(); // Call the API and handle any network failures. try { /** @var Location $response */ $response = $documentProcessorServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } ``` -------------------------------- ### Get Processor Version Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves the details of a specific processor version. This method allows you to fetch information about a particular version of a Document AI processor. ```APIDOC ## getProcessorVersion ### Description Gets a processor version detail. The async variant is DocumentProcessorServiceClient::getProcessorVersionAsync(). ### Method `getProcessorVersion(GetProcessorVersionRequest $request, array $callOptions = []): ProcessorVersion` ### Parameters #### Request Body - **request** (`Google\Cloud\DocumentAI\V1\GetProcessorVersionRequest`) - Required - A request to house fields associated with the call. - **callOptions** (`array`) - Optional - Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. ### Response #### Success Response (200) - **ProcessorVersion** (`Google\Cloud\DocumentAI\V1\ProcessorVersion`) - Details of the processor version. ### Example ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\GetProcessorVersionRequest; use Google\Cloud\DocumentAI\V1\ProcessorVersion; /** * @param string $formattedName The processor resource name. Please see * {@see DocumentProcessorServiceClient::processorVersionName()} for help formatting this field. */ function get_processor_version_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetProcessorVersionRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var ProcessorVersion $response */ $response = $documentProcessorServiceClient->getProcessorVersion($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorVersionName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]', '[PROCESSOR_VERSION]' ); get_processor_version_sample($formattedName); } ``` ``` -------------------------------- ### Get Document AI Evaluation Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves a specific evaluation using the Document Processor Service client. Ensure the resource name is correctly formatted. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\Evaluation; use Google\Cloud\DocumentAI\V1\GetEvaluationRequest; /** * @param string $formattedName The resource name of the * [Evaluation][google.cloud.documentai.v1.Evaluation] to get. * `projects/{project}/locations/{location}/processors/{processor}/processorVersions/{processorVersion}/evaluations/{evaluation}` * Please see {@see DocumentProcessorServiceClient::evaluationName()} for help formatting this field. */ function get_evaluation_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetEvaluationRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var Evaluation $response */ $response = $documentProcessorServiceClient->getEvaluation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::evaluationName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]', '[PROCESSOR_VERSION]', '[EVALUATION]' ); get_evaluation_sample($formattedName); } ``` -------------------------------- ### FoundationModelTuningOptions Constructor Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.TrainProcessorVersionRequest.FoundationModelTuningOptions Initializes a new instance of the FoundationModelTuningOptions class, optionally populating it with data. ```APIDOC ## __construct ### Description Constructor. ### Parameters #### Data - **data** (array) - Optional. Data for populating the Message object. - **train_steps** (int) - Optional. The number of steps to run for model tuning. Valid values are between 1 and 400. If not provided, recommended steps will be used. - **learning_rate_multiplier** (float) - Optional. The multiplier to apply to the recommended learning rate. Valid values are between 0.1 and 10. If not provided, recommended learning rate will be used. ``` -------------------------------- ### List Processor Versions (PHP) Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Use this method to list all versions of a processor. Ensure the parent string is correctly formatted. The async variant is available. ```php use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\ListProcessorVersionsRequest; use Google\Cloud\DocumentAI\V1\ProcessorVersion; /** * @param string $formattedParent The parent (project, location and processor) to list all * versions. Format: * `projects/{project}/locations/{location}/processors/{processor}` * Please see {@see DocumentProcessorServiceClient::processorName()} for help formatting this field. */ function list_processor_versions_sample(string $formattedParent): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new ListProcessorVersionsRequest()) ->setParent($formattedParent); // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ $response = $documentProcessorServiceClient->listProcessorVersions($request); /** @var ProcessorVersion $element */ foreach ($response as $element) { printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); } } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedParent = DocumentProcessorServiceClient::processorName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]' ); list_processor_versions_sample($formattedParent); } ``` -------------------------------- ### Get Processor Type using Document AI Client Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Retrieves details about a specific processor type. Ensure the processor type name is correctly formatted. This method can throw an ApiException on network failures. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\GetProcessorTypeRequest; use Google\Cloud\DocumentAI\V1\ProcessorType; /** * @param string $formattedName The processor type resource name. Please see * {@see DocumentProcessorServiceClient::processorTypeName()} for help formatting this field. */ function get_processor_type_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new GetProcessorTypeRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var ProcessorType $response */ $response = $documentProcessorServiceClient->getProcessorType($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorTypeName( '[PROJECT]', '[LOCATION]', '[PROCESSOR_TYPE]' ); get_processor_type_sample($formattedName); } ``` -------------------------------- ### Use New vs. Deprecated Client Namespaces in PHP Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/migrating Illustrates the namespace difference between the new v2 Cloud Clients (e.g., \\Client\\DocumentProcessorServiceClient) and the deprecated clients (e.g., Google\\Cloud\\DocumentAI\\V1\\DocumentProcessorServiceClient). ```php // This is the "new" client use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; // This is the deprecated client (marked with @deprecated) use Google\Cloud\DocumentAI\V1\DocumentProcessorServiceClient; ``` -------------------------------- ### Get Bounding Box Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the bounding polygon for this block. ```APIDOC ## getBoundingBox ### Description Identifies the bounding box for the block. ### Returns - **Type**: Google\Cloud\DocumentAI\V1\BoundingPoly|null - **Description**: The bounding polygon, or null if not present. ``` -------------------------------- ### Get Block ID Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the unique identifier for this block. ```APIDOC ## getBlockId ### Description ID of the block. ### Returns - **Type**: string - **Description**: The block ID. ``` -------------------------------- ### static::humanReviewConfigName Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Formats a string containing the fully-qualified path to represent a human_review_config resource. ```APIDOC ## static::humanReviewConfigName ### Description Formats a string containing the fully-qualified path to represent a human_review_config resource. ### Parameters - **project** (`string`) - Required. - **location** (`string`) - Required. - **processor** (`string`) - Required. ### Returns - **`string`** - The formatted human_review_config resource. ``` -------------------------------- ### Create a Document AI Processor Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Use this method to create a new processor. Requires the `documentai.processors.create` permission. The processor is enabled by default upon creation. ```php use Google\ApiCore\ApiException; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\CreateProcessorRequest; use Google\Cloud\DocumentAI\V1\Processor; /** * @param string $formattedParent The parent (project and location) under which to create the * processor. Format: `projects/{project}/locations/{location}` * Please see {@see DocumentProcessorServiceClient::locationName()} for help formatting this field. */ function create_processor_sample(string $formattedParent): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $processor = new Processor(); $request = (new CreateProcessorRequest()) ->setParent($formattedParent) ->setProcessor($processor); // Call the API and handle any network failures. try { /** @var Processor $response */ $response = $documentProcessorServiceClient->createProcessor($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedParent = DocumentProcessorServiceClient::locationName('[PROJECT]', '[LOCATION]'); create_processor_sample($formattedParent); } ``` -------------------------------- ### Get Page Span Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the page span information for this block. ```APIDOC ## getPageSpan ### Description Page span of the block. ### Returns - **Type**: DocumentLayoutBlock\LayoutPageSpan|null - **Description**: The page span object, or null if not present. ``` -------------------------------- ### Calling RPC Methods with Request Objects in PHP Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/migrating Demonstrates how to instantiate a new client, prepare a request message using a Request object, and call an RPC method (getLocation) while handling potential API exceptions. This pattern is used with the new client surface. ```php // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = new GetLocationRequest(); // Call the API and handle any network failures. try { /** @var Location $response */ $response = $documentProcessorServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` -------------------------------- ### Get Pages Overlap Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.DocumentOutputConfig.GcsOutputConfig.ShardingConfig Retrieves the number of overlapping pages between consecutive shards. ```APIDOC ## getPagesOverlap The number of overlapping pages between consecutive shards. ### Returns - **int** - The number of overlapping pages between consecutive shards. ``` -------------------------------- ### HumanReview Constructor Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.Revision.HumanReview Initializes a new instance of the HumanReview class, optionally populating it with provided data. ```APIDOC ## __construct ### Description Constructor. ### Parameters #### Data - **data** (array) - Optional. Data for populating the Message object. - **state** (string) - Human review state. For example, `requested`, `succeeded`, `rejected`. - **state_message** (string) - A message providing more details about the current state of processing. For example, the rejection reason when the state is `rejected`. ``` -------------------------------- ### List Processor Types (PHP) Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Lists the processor types available for a given project and location. Requires the `Google"]));Cloud"]));DocumentAI"]));V1"]));Client"]));DocumentProcessorServiceClient` and `Google"]));Cloud"]));DocumentAI"]));V1"]));ListProcessorTypesRequest` classes. Handles potential API exceptions. ```php use Google"]));ApiCore"]));ApiException; use Google"]));ApiCore"]));PagedListResponse; use Google"]));Cloud"]));DocumentAI"]));V1"]));Client"]));DocumentProcessorServiceClient; use Google"]));Cloud"]));DocumentAI"]));V1"]));ListProcessorTypesRequest; use Google"]));Cloud"]));DocumentAI"]));V1"]));ProcessorType; /**  * @param string $formattedParent The location of processor types to list.  *                                Format: `projects/{project}/locations/{location}`. Please see  *                                {@see DocumentProcessorServiceClient::locationName()} for help formatting this field.  */ function list_processor_types_sample(string $formattedParent): void {     // Create a client.     $documentProcessorServiceClient = new DocumentProcessorServiceClient();     // Prepare the request message.     $request = (new ListProcessorTypesRequest())         ->setParent($formattedParent);     // Call the API and handle any network failures.     try {         /** @var PagedListResponse $response */         $response = $documentProcessorServiceClient->listProcessorTypes($request);         /** @var ProcessorType $element */         foreach ($response as $element) {             printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());         }     } catch (ApiException $ex) {         printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());     } } /**  * Helper to execute the sample.  *  * This sample has been automatically generated and should be regarded as a code  * template only. It will require modifications to work:  *  - It may require correct/in-range values for request initialization.  *  - It may require specifying regional endpoints when creating the service client,  *    please see the apiEndpoint client configuration option for more details.  */ function callSample(): void {     $formattedParent = DocumentProcessorServiceClient::locationName('[PROJECT]', '[LOCATION]');     list_processor_types_sample($formattedParent); } ``` -------------------------------- ### __construct Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Initializes a new instance of the Document AI V1 client. This constructor allows for detailed configuration of the client, including API endpoint, authentication credentials, retry settings, and transport mechanisms. ```APIDOC ## __construct Constructor for the Google Cloud Document AI V1 client. ### Description Initializes a new instance of the Document AI V1 client. This constructor allows for detailed configuration of the client, including API endpoint, authentication credentials, retry settings, and transport mechanisms. ### Parameters #### `options` (array|Google\ApiCore\Options\ClientOptions) - Optional Options for configuring the service API wrapper. - `↳ apiEndpoint` (string) - The address of the API remote host. May optionally include the port. - `↳ credentials` (FetchAuthTokenInterface|CredentialsWrapper) - An object for authentication. Note: Providing a path to a credentials file or a decoded credentials file as a PHP array is deprecated. - `↳ credentialsConfig` (array) - Options used to configure credentials, including auth token caching. - `↳ disableRetries` (bool) - Determines whether or not retries defined by the client configuration should be disabled. Defaults to `false`. - `↳ clientConfig` (string|array) - Client method configuration, including retry settings. Can be a path to a JSON file or a PHP array. - `↳ transport` (string|TransportInterface) - The transport used for executing network requests. May be either the string `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected. - `↳ transportConfig` (array) - Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. - `↳ clientCertSource` (callable) - A callable which returns the client cert as a string. Used for providing a certificate and private key to the transport layer for mTLS. - `↳ logger` (false|LoggerInterface) - A PSR-3 compliant logger. If set to false, logging is disabled. - `↳ universeDomain` (string) - The service domain for the client. Defaults to 'googleapis.com'. ``` -------------------------------- ### deployProcessorVersionAsync Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Asynchronously deploys a processor version. This operation is long-running and returns a \`Google\ApiCore\OperationResponse\`. ```APIDOC ## deployProcessorVersionAsync ### Description Asynchronously deploys a processor version. This operation is long-running and returns a `Google\ApiCore\OperationResponse`. ### Parameters - `request` (`Google\Cloud\DocumentAI\V1\DeployProcessorVersionRequest`) - Required - The request object for deploying a processor version. - `optionalArgs` (`array`) - Optional - Additional arguments for the operation. ``` -------------------------------- ### Get Table Block Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Document.DocumentLayout.DocumentLayoutBlock Retrieves the table content block associated with this layout block. ```APIDOC ## getTableBlock ### Description Block consisting of table content/structure. ### Returns - **Type**: DocumentLayoutBlock\LayoutTableBlock|null - **Description**: The table content block, or null if not present. ``` -------------------------------- ### Undeploy Processor Version Sample - PHP Source: https://docs.cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.Client.DocumentProcessorServiceClient Use this snippet to undeploy a processor version. It requires the processor version's resource name. The code handles the asynchronous operation and reports success or failure. ```php use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; use Google\Cloud\DocumentAI\V1\UndeployProcessorVersionRequest; use Google\Cloud\DocumentAI\V1\UndeployProcessorVersionResponse; use Google\Rpc\Status; /** * @param string $formattedName The processor version resource name to be undeployed. Please see * {@see DocumentProcessorServiceClient::processorVersionName()} for help formatting this field. */ function undeploy_processor_version_sample(string $formattedName): void { // Create a client. $documentProcessorServiceClient = new DocumentProcessorServiceClient(); // Prepare the request message. $request = (new UndeployProcessorVersionRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ $response = $documentProcessorServiceClient->undeployProcessorVersion($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { /** @var UndeployProcessorVersionResponse $result */ $result = $response->getResult(); printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); } else { /** @var Status $error */ $error = $response->getError(); printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString()); } } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedName = DocumentProcessorServiceClient::processorVersionName( '[PROJECT]', '[LOCATION]', '[PROCESSOR]', '[PROCESSOR_VERSION]' ); undeploy_processor_version_sample($formattedName); } ```