Merge PDF files to HTML together in Python

High-speed and cross-platform Python API that helps in developing applications with the ability to create, merge, inspect, or convert Microsoft PowerPoint and OpenOffice presentation files without the use of any software like Microsoft or Open Office, Adobe PDF.

Merge PDF to HTML in Python

Aspose.Slides for Python via .NET is a powerful Python library for creating and manipulating presentation files. Moreover, it provides flexible ways to combine multiple PDF presentations. When you merge one presentation to another, you are effectively combining their slides in a single presentation to obtain one file. Aspose.Slides allows you merge two presentations in different ways. You get to merge presentations with all their shapes, styles, texts, formatting, comments, animations, etc. without having to worry about loss of quality or data.

Merge PDF files to HTML using Python

To merge the PowerPoint presentations, you will need to clone the slides from one presentation to the other.

Python code for merge multiple PDF into single HTML file


import aspose.slides as slides


with slides.Presentation() as pres1:
    pres1.slides.remove_at(0)
    pres1.slides.add_from_pdf("document1.pdf")
    with slides.Presentation() as pres2:
        pres2.slides.remove_at(0)
        pres2.slides.add_from_pdf("document2.pdf")
        for slide in pres2.slides:
            # clone slide
            pres1.slides.add_clone(slide)
    pres1.save("presentation.html", slides.export.SaveFormat.HTML5)

How to merge PDF to HTML using Aspose.Slides for Python API

These are the steps to merge two PDF files and save result as HTML in Python.

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

    pip install aspose.slides
    

  2. Add a library reference (import the library) to your Python project.

    import aspose.slides as slides
    

  3. Open the source PDF files in Python.

    pres1 = slides.Presentation('pres1.pdf')
    pres2 = slides.Presentation('pres2.pdf')
    

  4. Combine PDF files using add_clone method.

    for slide in pres2.slides:
        pres1.slides.add_clone(slide)
    

  5. Save presentation and get result as single HTML file.

    pres1.save("presentation.html", slides.export.SaveFormat.HTML5)