Image-to-PDF conversion
Intelligent Media Management (IMM) converts multiple images into a single PDF file through the CreateImageToPDFTask API. The conversion runs asynchronously -- submit the request, then poll or subscribe for the result.
How it works
-
Upload source images to an Object Storage Service (OSS) bucket.
-
Call
CreateImageToPDFTaskwith the image URIs and a target PDF path. -
Monitor the asynchronous task until it completes.
-
Retrieve the output PDF from the specified OSS path.
Use cases
-
Batch sharing: Combine multiple images into one PDF for distribution.
-
Print preparation: Preserve original formatting and layout across printed pages.
-
Cross-platform viewing: PDF renders consistently on Windows, macOS, and Linux.
Prerequisites
Before you begin, make sure you have:
-
An AccessKey pair (Create an AccessKey pair)
-
An OSS bucket with source images uploaded (Upload objects)
-
IMM activated (Activate IMM)
-
An IMM project (Create a project)
To manage projects programmatically, call CreateProject or ListProjects.
Create a conversion task
Call the CreateImageToPDFTask API to submit an image-to-PDF conversion task. Each task supports up to 100 input images. Supported image formats: JPG, JP2, PNG, TIFF, WebP, BMP, and SVG.
Request parameters
|
Parameter |
Type |
Required |
Description |
|
|
String |
Yes |
Name of your IMM project |
|
|
Array<Object> |
Yes |
List of source image objects. Each object contains a |
|
|
String |
Yes |
OSS path for the output PDF |
Request example
{
"ProjectName": "test-project",
"Sources": "[{\"URI\": \"oss://test-bucket/test-object.jpg\"}]",
"TargetURI": "oss://test-bucket/test-target-object.pdf"
}
Response example
{
"TaskId": "ImageToPDF-1c73b551-381d-46cc-86ed-16905*****",
"RequestId": "657DE82D-5960-0309-810C-639637*****",
"EventId": "124-1S7JgMQdZ3kWQbmUqXxI3******"
}
Monitor task status
Task information is retained for 7 days after the task starts. After that, task details are no longer available. Track task progress through any of the following methods:
-
Poll the API: Call GetTask or ListTasks to query task status.
-
Simple Message Queue (SMQ): Configure an SMQ subscription in the same region as your IMM project. For details, see Asynchronous message examples. For information about the SMQ SDK, see Step 4: Receive and delete the message.
-
ApsaraMQ for RocketMQ 4.0: Create an instance, topic, and group in the same region as your IMM project. For details, see Asynchronous message examples. For information about ApsaraMQ for RocketMQ, see Use HTTP client SDKs to send and subscribe to normal messages.
-
EventBridge: Receive task notifications through EventBridge. For details, see IMM events.
SDK example (Python)
The following example uses the IMM SDK for Python to convert images to a PDF file.
import os
import sys
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint.
config.endpoint = f'imm.cn-zhangjiakou.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
sources_0 = imm_20200930_models.CreateImageToPDFTaskRequestSources(
uri='oss://test-bucket/test-object.jpg'
)
create_image_to_pdftask_request = imm_20200930_models.CreateImageToPDFTaskRequest(
project_name='test-project',
target_uri='oss://test-bucket/test-target-object.pdf',
sources=[
sources_0
]
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
client.create_image_to_pdftask_with_options(create_image_to_pdftask_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
sources_0 = imm_20200930_models.CreateImageToPDFTaskRequestSources(
uri='oss://test-bucket/test-object.jpg'
)
create_image_to_pdftask_request = imm_20200930_models.CreateImageToPDFTaskRequest(
project_name='test-project',
target_uri='oss://test-bucket/test-target-object.pdf',
sources=[
sources_0
]
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
await client.create_image_to_pdftask_with_options_async(create_image_to_pdftask_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Billing
Image-to-PDF conversion incurs fees on both the OSS side and the IMM side.
OSS fees
For detailed pricing, see OSS Pricing.
|
API |
Billable item |
Description |
|
GetObject |
GET requests |
Charged per successful request |
|
GetObject |
Data retrieval of IA objects |
Charged based on the size of retrieved Infrequent Access (IA) data |
|
GetObject |
Retrieved Archive data for real-time access |
Charged based on the size of retrieved Archive objects when real-time access is enabled |
|
GetObject |
Transfer acceleration |
Charged based on data size when transfer acceleration is enabled |
|
PutObject |
PUT requests |
Charged per successful request |
|
PutObject |
Storage fees |
Charged based on storage class, object size, and storage duration |
|
HeadObject |
GET requests |
Charged per successful request |
IMM fees
For detailed pricing, see IMM billable items.
Starting from 11:00 on July 28, 2025 (UTC+8), the IMM image-to-PDF service changed from a free model to a paid model. For details, see IMM billing adjustment announcement.
|
API |
Billable item |
Description |
|
CreateImageToPDFTask |
ImageToPDF |
Charged per image converted |