Document Processing - Image to PDF API
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 header: |
| Request header |
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 |
|
| Yes | None | Fixed to |
|
|
| Mutually exclusive with | None | The URL of a downloadable image. An HTTPS URL on the public network is recommended. | See request example |
|
| This option is mutually exclusive with | None | The standard Base64 string of a single image, without the | 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 |
|
| Always returned | Provide this ID when you contact technical support. |
|
| Always returned | Contains the document processing time. |
|
| Always returned | The document processing time in milliseconds. |
|
| Always returned | The value is fixed to |
|
| Always returned | The Base64 encoding of the converted PDF file. |
|
| Always returned | Fixed to |
|
| Always returned | Fixed to |
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 |
|
| The image source or a required parameter is missing. | Check |
|
| A parameter is invalid or the image is too large. | Verify the case sensitivity of |
|
| The API Key is invalid. | Check the |
| As returned in the response | Insufficient permissions or quota. | Check the API activation status, call permissions, and available quota. |
| As returned in the response | The request format is not supported. The response body may be empty. | Use |
|
| Requests are too frequent. | Reduce the call frequency and implement a backoff and retry strategy. |
| 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. |
| As returned in the response | The service is temporarily unavailable. | Retry later. If the issue persists, contact technical support. |
| 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 theengineTypeparameter has an incorrect case (for example, writingScanDocConvertPDFasscandocconvertpdf) 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.