Skip to content

aspose-html/Aspose.HTML-for-Java

Repository files navigation

Product Page | Docs | Release Notes | Download | Demos | API Reference | Blog | Free Support | Temporary License

Aspose.HTML for Java – Examples, Starter Projects, Benchmarks

This repository contains code examples, starter templates, and microbenchmarks demonstrating how to use Aspose.HTML for Java – a powerful library for working with HTML, MHTML, EPUB, Markdown, SVG, and various output formats in Java applications.

Aspose.HTML for Java enables developers to load, parse, generate, modify, and convert HTML documents in any Java environment, including desktop, server-side, microservices, and cloud applications.

This repository works hand in hand with the official Aspose.HTML for Java documentation. The examples provided here are intended to complement the documentation, extend it, and provide ready-to-use code snippets for processing, parsing, converting, and rendering HTML-based documents, working with the DOM, and more.

Key Features Demonstrated in This Repository

  • Create or load HTML documents from multiple sources.
  • Fully manipulate the HTML DOM: create, edit, remove, and replace nodes.
  • Extract data from HTML, including text and CSS styles for specific elements.
  • Navigate documents using Element Traversal, XPath, CSS selectors, and DOM traversal.
  • Execute and interact with JavaScript inside HTML documents.
  • Configure sandbox settings to control document processing and script behavior.
  • Convert HTML, XHTML, SVG, MHTML, Markdown, and EPUB to PDF, XPS, DOCX, and various image formats (PNG, JPEG, BMP, TIFF, GIF).
  • Fine-tune conversions with page size, resolution, custom stylesheets, resource handling, and script execution settings.
  • Convert between HTML and Markdown for migration or content-editing workflows.
  • Control rendering timeouts to optimize performance and resource usage.
  • Download website content and process online HTML resources.

Each example in the repository serves as a practical, ready-to-run usage scenario. More information about a wide range of document processing, conversion, and DOM manipulation functionality can be found here.

Repository Structure

  • Aspose.HTML-for-Java.Start – Basic startup examples for new users.
  • Aspose.HTML-for-Java.Example – Full collection of practical examples (HTML conversion, parsing, DOM operations, CSS handling, etc.).
  • Aspose.HTML-for-Java.Microbenchmark – Performance tests and benchmarks for evaluating Aspose.HTML for Java under different workloads.
  • Aspose.HTML-for-Java.WebService-on-Docker – A ready-to-use Dockerized web service that exposes Aspose.HTML functionality via REST API.
  • docs – Documentation files that help developers install, configure, and effectively use Aspose.HTML for Java.

Requirements

Quick Start with Aspose.HTML for Java

Install Aspose.HTML for Java

Gradle. – Define Aspose.HTML for Java API dependency in your build.gradle script:

compile(group: 'com.aspose', name: 'aspose-html', version: '25.12', classifier: 'jdk16')

Maven:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-html</artifactId>
    <version>25.12</version>
    <classifier>jdk17</classifier>
</dependency>

Convert HTML to PDF with one line of Java code

import com.aspose.html.converters.Converter;
import com.aspose.html.saving.PdfSaveOptions;

// Invoke the convertHTML() method to convert the HTML to PDF
Converter.convertHTML("<h1>Convert HTML to PDF!</h1>", ".", new PdfSaveOptions(), "convert-with-single-line.pdf");

Download web page in Java

Extract and save a wab page with default save options in Java

import com.aspose.html.HTMLDocument;

// Initialize an HTML document from a URL
final HTMLDocument document = new HTMLDocument("https://docs.aspose.com/html/net/message-handlers/");
// Prepare a path to save the downloaded file
String savePath = "root/result.html";

// Save the HTML document to the specified file
document.save(savePath);

See all examples in Aspose.HTML-for-Java.Example

Contributing

Contributions are welcome! Feel free to submit PRs with new examples, fixes, or enhancements.

Product Page | Docs | Release Notes | Download | Demos | API Reference | Blog | Free Support | Temporary License

Releases

No releases published

Packages

No packages published

Contributors 17