Document Processing - Image to PDF API

Updated at:

Call the processDocument API to convert an image to a PDF. The API returns the resulting file as a Base64-encoded string.

1. API

API name: processDocument

Description: Converts an image to a PDF file by using the fixed engineType value ScanDocConvertPDF.

Item

Description

request method

POST

service address

https://cloud-iqs.aliyuncs.com/document/process

Request format

Request header: Content-Type: application/json

authentication method

Request header X-API-Key

The billing method is "Vertical Search," and you are charged for each successful API call. For pricing details, see "Vertical Search Billing Description" at the end of this document.

2. API definition

Request parameters

Parameter

Type

Required

Default

Description

Example

engineType

string

Yes

None

Fixed to ScanDocConvertPDF. The value is case-sensitive.

ScanDocConvertPDF

dataUrl

string

Mutually exclusive with dataBase64

None

The URL of a downloadable image. An HTTPS URL on the public network is recommended.

See request example

dataBase64

string

This option is mutually exclusive with dataUrl.

None

The standard Base64 string of a single image, without the data: prefix. The maximum size of the original image is 10 MiB (10,485,760 bytes).

Complete image Base64

Note

Response parameters

The following table defines the fields in a successful response. Field names are case-sensitive.

Field

Type

Return rule

Description

requestId

string

Always returned

Provide this ID when you contact technical support.

searchInformation

object

Always returned

Contains the document processing time.

searchInformation.searchTime

int64

Always returned

The document processing time in milliseconds.

functionOption

string

Always returned

The value is fixed to pdf and is case-sensitive. This is not the engineType value in the request.

fileBase64

string

Always returned

The Base64 encoding of the converted PDF file.

fileName

string

Always returned

Fixed to result.pdf.

mimeType

string

Always returned

Fixed to application/pdf.

Parse the JSON response and Base64-decode the fileBase64 value to obtain the file's binary bytes. Save the bytes as result.pdf based on fileName. Do not save the Base64 string itself as the PDF file content. The file type is specified by mimeType.

3. Examples

The image URL in the example is a placeholder. Replace it with an actual, downloadable URL for your API call.

Request parameters:

{
  "engineType": "ScanDocConvertPDF",
  "dataUrl": "https://example.com/images/ScanDocConvertPDF.png"
}

Response parameters: The following example shows the complete response structure. The processing time and request ID are for illustrative purposes only. [CompleteFileBase64] is a placeholder string that cannot be decoded into an actual file and is not a valid file encoding. The actual response returns the complete Base64-encoded file.

{
  "requestId": "example-request-id",
  "searchInformation": {"searchTime": 120},
  "functionOption": "pdf",
  "fileBase64": "[Complete-File-Base64]",
  "fileName": "result.pdf",
  "mimeType": "application/pdf"
}

4. API call

Pass an authorized API key in the X-API-Key request header. The following example reads the credential from the API_KEY environment variable. Do not hardcode the actual credential in a front-end web page or public code.

curl -X POST 'https://cloud-iqs.aliyuncs.com/document/process' \
  --header "X-API-Key: $API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "engineType": "ScanDocConvertPDF",
    "dataUrl": "https://example.com/images/ScanDocConvertPDF.png"
  }'

When using Base64, replace dataUrl with dataBase64, pass the complete image encoding that conforms to the rules above, and do not provide two non-empty image sources at the same time. The call method is still POST JSON, using only the request fields defined on this page.

5. Error codes

Check the HTTP status code and the response body format before you read the error information. A JSON response for a business error contains the errorCode and errorMessage fields. The optional code and message fields have the same meaning. A 403 response caused by issues such as permissions or quotas is not guaranteed to contain all of these fields. Therefore, you should prioritize reading the returned errorCode and errorMessage fields. If they are missing, read the code and message fields. The requestId field is not guaranteed in all error responses, and the response body may be non-JSON or empty.

Example of a parameter error (includes optional mirrored fields):

{
  "errorCode": "InvalidParameter",
  "errorMessage": "Image too large",
  "code": "InvalidParameter",
  "message": "Image too large"
}

HTTP status

Error code

Description

Solution

400

MissingParameter

The image source or a required parameter is missing.

Check engineType, and provide a non-empty image source.

400

InvalidParameter

A parameter is invalid or the image is too large.

Verify the case sensitivity of ScanDocConvertPDF, the image source mutual exclusion rules, Base64 padding, and the original image size. Do not pass inputConfig or other additional parameters.

403

Retrieval.InvalidAPIKey

The API Key is invalid.

Check the X-API-Key request header and the credential.

403

As returned in the response

Insufficient permissions or quota.

Check the API activation status, call permissions, and available quota.

415

As returned in the response

The request format is not supported. The response body may be empty.

Use Content-Type: application/json.

429

Retrieval.Throttling.scan (common)

Requests are too frequent.

Reduce the call frequency and implement a backoff and retry strategy.

502

As returned in the response

Failed to process the image or retrieve the result.

Check if the image is downloadable and inspect its content. If the issue persists, contact technical support and provide the request ID, if available.

503

As returned in the response

The service is temporarily unavailable.

Retry later. If the issue persists, contact technical support.

500

As returned in the response

An unexpected error occurred during service processing.

Contact technical support and provide the request ID (if available) and the error message from the response body.

Note The service may return non-JSON text if the engineType parameter has an incorrect case (for example, writing ScanDocConvertPDF as scandocconvertpdf) or if the JSON request body is truncated. Do not directly parse all error responses as JSON. If the response body is empty, you should also handle the response based on the HTTP status code.

6. Related documents