Merge PDF Files and Export to JPG in Python

Import pages from multiple PDF files and render the combined content as JPEG images with a cross-platform Python API

Merge PDF to JPG in Python

Aspose.Slides for Python via .NET lets you combine PDF files by importing their pages into a Presentation. SlideCollection.add_from_pdf converts each PDF page into a slide and appends it to the presentation. After importing all source files, render each slide with Slide.get_image and save the resulting IImage object in JPEG format.

Merge PDF Files to JPG Using Python

Create a presentation without its default blank slide, import the source PDF files in the required order, and render every imported page as a separate JPEG image.

Python code for merging PDF files and exporting the pages as JPG images

image_scale = 2

with slides.Presentation() as presentation:
    presentation.slides.remove_at(0)
    presentation.slides.add_from_pdf("document1.pdf")
    presentation.slides.add_from_pdf("document2.pdf")

    for slide in presentation.slides:
        file_path = f"merged_page_{slide.slide_number}.jpg"
        with slide.get_image(image_scale, image_scale) as slide_image:
            slide_image.save(file_path, slides.ImageFormat.JPEG)

How to Merge PDF Files and Export to JPG with Aspose.Slides for Python

Follow these steps to merge two PDF files and export the imported pages as JPG images.

  1. Install Aspose.Slides for Python via .NET by following the installation guide .

    pip install aspose-slides
    

  2. Make the aspose.slides namespace available in your Python project.

  3. Create a Presentation and remove its default blank slide.

  4. Pass each source PDF file to SlideCollection.add_from_pdf in the required order.

  5. Render each imported Slide with Slide.get_image, then call IImage.save with ImageFormat.JPEG to create a separate JPG file for that page.