Split HTML into parts in Java

Fast Java library to split one HTML file into a group of smaller files according to the given criteria.

Use Java library to split HTML files into parts. You can integrate the extracted HTML pages with other data and, as a result, get documents of the form and content that you require. Splitting HTML into parts makes it easier to collaborate on HTML files.

View code snippet

Split HTML in Java

This software library provides Java developers with a set of functions to split HTML into parts. Splitting a HTML into separate files can be used to make it easier to work with sections of a document in parallel. For example, if several people are working on one HTML at the same time, splitting HTML will allow them to speed up the process. The HTML splitting may be part of a technology for extracting text from HTML files and integrating data into automated information systems or databases.

Our library provides Java developers with all the necessary functions to split HTML into parts and extract pages according to the specified mode. This is a stand-alone Java solution that does not require Microsoft Word, Acrobat Reader or other applications installed.

Split HTML into parts using Java

Split HTML content using different criteria in Java code. You can use the following page extraction modes for HTML files: 'split by headings', 'split by sections', 'split page by page', 'split by page ranges'.

After splitting your HTML into parts, you can export the result to the required file format using the 'Document.Save' method. You can also control how the HTML parts are exported to HTML and EPUB formats using the 'DocumentPartSavingCallback' property, which will also allow you to redirect output streams.

Split HTML documents easily with our solution for Java. The following example shows how to split a HTML using Java:

Java code example to split a HTML file
Upload a file you want to split
Run code
Select the target format from the list
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
 <artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
import com.aspose.words.*;

Document doc = new Document("Input.html");

for (int page = 0; page < doc.getPageCount(); page++)
    Document extractedPage = doc.extractPages(page, 1);
    extractedPage.save(String.format("Output_%d.html", page + 1));
Run code

How to split HTML Java

  1. Install Java library to split HTML files programmatically.
  2. Add a library reference (import the library) to your Java project.
  3. Open the HTML in Java.
  4. Call the extractPages() method to extract specific pages from HTML.
  5. Get the result of HTML splitting as separate files.

Java library to split HTML documents

We host our Java packages in Maven repositories. 'Aspose.Words for Java' is a common JAR file containing byte-code. Please follow the step-by-step instructions on how to install it to your Java developer environment.

System Requirements

Java SE 7 and more recent Java versions are supported. We also provide a separate package for Java SE 6 in case you are obliged to use this outdated JRE.

Our Java package is cross-platform and runs on all operating systems with JVM implementation, including Microsoft Windows, Linux, macOS, Android and iOS.

For information on optional package dependencies, such as JogAmp JOGL, Harfbuzz font engine, Java Advanced Imaging JAI, please refer to Product Documentation.

Other supported HTML split operations

You can also split HTML to other file formats:


Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.