Merge Images to PDF in Python

Combine multiple images and save the result as a PDF document with a cross-platform Python API

Merge Images to PDF Using Aspose.Slides

Aspose.Slides for Python via .NET lets you place multiple images on one Slide and export the combined layout as a single-page PDF document. Load each source image with Images.from_file, add it to Presentation.images, create picture frames, and call Presentation.save with SaveFormat.PDF.

Merge Images into a PDF Document in Python

Create a Presentation, place the source images side by side on its first Slide, and export the slide as a one-page PDF document.

Python code for merging images into a PDF document

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("image1.png") as first_source_image:
        first_presentation_image = presentation.images.add_image(first_source_image)

    slide.shapes.add_picture_frame(
        slides.ShapeType.RECTANGLE, 0, 0, 360, 270, first_presentation_image)

    with slides.Images.from_file("image2.png") as second_source_image:
        second_presentation_image = presentation.images.add_image(second_source_image)

    slide.shapes.add_picture_frame(
        slides.ShapeType.RECTANGLE, 360, 0, 360, 270, second_presentation_image)

    presentation.save("merged.pdf", slides.export.SaveFormat.PDF)

How to Merge Images into a PDF Document in Python

Follow these steps to combine multiple images into one PDF document.

  1. Install Aspose.Slides for Python via .NET .

  2. Import the aspose.slides module in your Python project.

  3. Create a Presentation and access its first Slide.

  4. Load the source images with Images.from_file, add them to Presentation.images, and arrange them in picture frames.

  5. Call Presentation.save with SaveFormat.PDF to create the combined PDF document.

Merge Other Files

You can also combine files in other formats.