Merge PNG Images into PDF in Python

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

Merge PNG Images into PDF Using Aspose.Slides

Aspose.Slides for Python via .NET lets you place multiple PNG 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 PNG Images into a PDF Document in Python

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

Python code for merging PNG 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 PNG Images into a PDF Document in Python

Follow these steps to combine multiple PNG 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 PNG 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.