adobe.pdfservices.operation package

Subpackages

Submodules

adobe.pdfservices.operation.client_config module

class adobe.pdfservices.operation.client_config.ClientConfig

Bases: object

Encapsulates the API request configurations

class Builder

Bases: object

Builds a ClientConfig instance.

build()

Returns a new ClientConfig instance built from the current state of this builder.

Returns:

A ClientConfig instance.

Return type:

ClientConfig

from_file(client_config_file_path: str)

Sets the connect timeout and read timeout using the JSON client config file path. All the keys in the JSON structure are optional.

Parameters:

client_config_file_path (str) – JSON client config file path

Returns:

This Builder instance to add any additional parameters.

Return type:

ClientConfig.Builder

JSON structure:

{
    "connectTimeout": "4000",
    "readTimeout": "20000",
    "region": "eu",
    "processingTimeout": "600000"
}
with_connect_timeout(connect_timeout: int)

Sets the connect timeout. It should be greater than zero.

Parameters:

connect_timeout (int) – determines the timeout in milliseconds until a connection is established in the API calls. Default value is 4000 milliseconds

Returns:

This Builder instance to add any additional parameters.

Return type:

ClientConfig.Builder

with_pdf_services_uri(pdf_services_uri: str)

Sets the pdf service uri.

Parameters:

pdf_services_uri (str) – PDF service URI.

Returns:

This Builder instance to add any additional parameters.

Return type:

ClientConfig.Builder

with_processing_timeout(processing_timeout: int)

Sets the processing timeout. It should be greater than or equal to 600000 (10 minutes).

Parameters:

processing_timeout (int) – Defines the processing timeout in milliseconds to process the documents. Default value is 600000 milliseconds (10 minutes)

Returns:

This Builder instance to add any additional parameters.

Return type:

ClientConfig.Builder

with_read_timeout(read_timeout: int)

Sets the read timeout. It should be greater than zero.

Parameters:

read_timeout (int) – Defines the read timeout in milliseconds, The number of milliseconds the client will wait for the server to send a response after the connection is established. Default value is 10000 milliseconds

Returns:

This Builder instance to add any additional parameters.

Return type:

ClientConfig.Builder

with_region(region: Region)

Updates the relevant value for the region.

Parameters:

region (Region) – Service region(US or EU). Default value is US.

Returns:

This Builder instance to add any additional parameters.

Return type:

ClientConfig.Builder

static builder()

Creates a new ClientConfig builder.

Returns:

A ClientConfig.Builder instance.

Return type:

ClientConfig.Builder

adobe.pdfservices.operation.execution_context module

class adobe.pdfservices.operation.execution_context.ExecutionContext

Bases: object

Represents the execution context of an Operation. An execution context typically consists of the desired authentication credentials and client configurations such as timeouts.

For each set of credentials, a ExecutionContext instance can be reused across operations.

Sample Usage:

try:
    base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    credentials = Credentials.service_principal_credentials_builder().                 with_client_id(os.getenv('PDF_SERVICES_CLIENT_ID')).                 with_client_secret(os.getenv('PDF_SERVICES_CLIENT_SECRET')).                 build()

    execution_context = ExecutionContext.create(credentials)
    extract_pdf_operation = ExtractPDFOperation.create_new()

    source = FileRef.create_from_local_file(base_path + "/resources/extractPdfInput.pdf")
    extract_pdf_operation.set_input(source)

    extract_pdf_options: ExtractPDFOptions = ExtractPDFOptions.builder() \
        .with_elements_to_extract([ExtractElementType.TEXT, ExtractElementType.TABLES]) \
        .with_elements_to_extract_renditions([ExtractRenditionsElementType.TABLES, ExtractRenditionsElementType.FIGURES]) \
        .with_get_char_info(True) \
        .build()
    extract_pdf_operation.set_options(extract_pdf_options)

    result: FileRef = extract_pdf_operation.execute(execution_context)

    result.save_as(base_path + "/output/ExtractTextTableWithFigureTableRendition.zip")
except (ServiceApiException, ServiceUsageException, SdkException):
    logging.exception("Exception encountered while executing operation")
static create(credentials: Credentials, client_config: ClientConfig | None = None)

Creates a context instance using the provided Credentials and ClientConfig

Parameters:
  • credentials (Credentials) – A Credentials instance

  • client_config (ClientConfig, optional) – A ClientConfig instance for providing custom http timeouts, defaults to None

Returns:

A new ExecutionContext instance

Return type:

ExecutionContext

adobe.pdfservices.operation.operation module

class adobe.pdfservices.operation.operation.Operation

Bases: ABC

abstract execute(execution_context: ExecutionContext)

Module contents