Merge HTML via Python

Merge HTML documents. Use Aspose.PDF for Python for .NET to modify HTML files programmatically

Merge HTML files using Python for .NET

To merge HTML files, we recommend using Aspose.PDF for Python API, a robust and user-friendly document manipulation API designed for Python applications. An outstanding feature of Aspose.PDF is its capability to combine PDFs effortlessly. You can install Aspose.PDF for Python via .NET by simply accessing [PyPI], searching for aspose-pdf, and installing it without requiring any complex configurations. The Python library enables document conversion from any supported input format to any supported output format. Aspose.PDF for Python via .NET offers comprehensive solutions for document conversion tasks. It supports a wide array of popular document formats for both loading and saving purposes. Note that this section focuses on popular conversions; detailed information about converting specific formats is provided here. There are numerous combinations available for file conversions. For a complete list of supported formats, refer to Supported File Formats. Additional details on installing the library can be found in the Documentation pages. Furthermore, you may use the following command from the console or terminal.

Console

pip install aspose-pdf

How to Merge HTML files via Python


You need Aspose.PDF for Python via .NET to try the code in your environment.

  1. Open first document.
  2. Open second document.
  3. Add pages of second document to the first.
  4. Save concatenated output file

Python - example code to merge HTML file

Input file:

File not added

File not added

Output format:

Output file:

import aspose.pdf as apdf


from os import path
html_load_options = apdf.HtmlLoadOptions()
document_infiles = [
    apdf.Document(path.join(self.data_dir, infile), html_load_options)
    for infile in infiles
]
path_outfile = path.join(self.data_dir, outfile)
document = apdf.Document.merge_documents(documents=document_infiles)
document.save(path_outfile)
print(str(infiles) + " merged into " + outfile)