Skip to content

Commit ff6a6e0

Browse files
olga-ananinatpavel-aspose
authored andcommitted
Added README.md and docs
1 parent 76e0564 commit ff6a6e0

File tree

5 files changed

+293
-0
lines changed

5 files changed

+293
-0
lines changed

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[Product Page](https://products.aspose.com/html/java/) | [Docs](https://docs.aspose.com/html/java/) | [Release Notes](https://releases.aspose.com/html/java/release-notes/) | [Download](https://releases.aspose.com/html/java/) | [Demos](https://products.aspose.app/html/applications) | [API Reference](https://reference.aspose.com/html/java/) | [Blog](https://blog.aspose.com/categories/aspose.html-product-family/) | [Free Support](https://forum.aspose.com/c/html/29) | [Temporary License](https://purchase.aspose.com/temporary-license/)
2+
3+
# Aspose.HTML for Java – Examples, Starter Projects, Benchmarks
4+
5+
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.
6+
7+
[Aspose.HTML for Java](https://products.aspose.com/html/java/) enables developers to load, parse, generate, modify, and convert HTML documents in any Java environment, including desktop, server-side, microservices, and cloud applications.
8+
9+
## Key Features Demonstrated in This Repository
10+
11+
* Create or load HTML documents from multiple sources.
12+
* Fully manipulate the HTML DOM: create, edit, remove, and replace nodes.
13+
* Extract data from HTML, including text and CSS styles for specific elements.
14+
* Navigate documents using Element Traversal, XPath, CSS selectors, and DOM traversal.
15+
* Execute and interact with JavaScript inside HTML documents.
16+
* Configure sandbox settings to control document processing and script behavior.
17+
* Convert HTML, XHTML, SVG, MHTML, Markdown, and EPUB to PDF, XPS, DOCX, and various image formats (PNG, JPEG, BMP, TIFF, GIF).
18+
* Fine-tune conversions with page size, resolution, custom stylesheets, resource handling, and script execution settings.
19+
* Convert between HTML and Markdown for migration or content-editing workflows.
20+
* Control rendering timeouts to optimize performance and resource usage.
21+
* Download website content and process online HTML resources.
22+
23+
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](https://github.com/aspose-html/Aspose.HTML-for-Java/blob/master/docs/supported-features.md).
24+
25+
## Repository Structure
26+
27+
- **Aspose.HTML-for-Java.Start** – Basic startup examples for new users.
28+
- **Aspose.HTML-for-Java.Example** – Full collection of practical examples (HTML conversion, parsing, DOM operations, CSS handling, etc.).
29+
- **Aspose.HTML-for-Java.Microbenchmark** – Performance tests and benchmarks for evaluating Aspose.HTML for Java under different workloads.
30+
- **Aspose.HTML-for-Java.WebService-on-Docker** – A ready-to-use Dockerized web service that exposes Aspose.HTML functionality via REST API.
31+
- **docs** – Documentation files that help developers install, configure, and effectively use Aspose.HTML for Java.
32+
33+
## Requirements
34+
35+
- J2SE 1.6 or above
36+
- Maven or Gradle
37+
- Aspose.HTML for Java (you can download the latest version at: https://releases.aspose.com/html/java/)
38+
39+
## Quick Start with Aspose.HTML for Java
40+
41+
### Install Aspose.HTML for Java
42+
43+
**Gradle.** – Define Aspose.HTML for Java API dependency in your build.gradle script:
44+
45+
46+
```java
47+
compile(group: 'com.aspose', name: 'aspose-html', version: '25.12', classifier: 'jdk16')
48+
```
49+
50+
**Maven:**
51+
52+
```java
53+
<dependency>
54+
<groupId>com.aspose</groupId>
55+
<artifactId>aspose-html</artifactId>
56+
<version>25.12</version>
57+
<classifier>jdk17</classifier>
58+
</dependency>
59+
```
60+
### Convert HTML to PDF with one line of Java code
61+
62+
```java
63+
import com.aspose.html.converters.Converter;
64+
import com.aspose.html.saving.PdfSaveOptions;
65+
66+
// Invoke the convertHTML() method to convert the HTML to PDF
67+
Converter.convertHTML("<h1>Convert HTML to PDF!</h1>", ".", new PdfSaveOptions(), "convert-with-single-line.pdf");
68+
```
69+
70+
### Download web page in Java
71+
72+
Extract and save a wab page with default save options in Java
73+
74+
```java
75+
import com.aspose.html.HTMLDocument;
76+
77+
// Initialize an HTML document from a URL
78+
final HTMLDocument document = new HTMLDocument("https://docs.aspose.com/html/net/message-handlers/");
79+
// Prepare a path to save the downloaded file
80+
String savePath = "root/result.html";
81+
82+
// Save the HTML document to the specified file
83+
document.save(savePath);
84+
```
85+
86+
See all examples in [Aspose.HTML-for-Java.Example](https://github.com/aspose-html/Aspose.HTML-for-Java/tree/master/Aspose.HTML-for-Java.Example
87+
)
88+
## Contributing
89+
90+
Contributions are welcome! Feel free to submit PRs with new examples, fixes, or enhancements.
91+
92+
[Product Page](https://products.aspose.com/html/java/) | [Docs](https://docs.aspose.com/html/java/) | [Release Notes](https://releases.aspose.com/html/java/release-notes/) | [Download](https://releases.aspose.com/html/java/) | [Demos](https://products.aspose.app/html/applications) | [API Reference](https://reference.aspose.com/html/java/) | [Blog](https://blog.aspose.com/categories/aspose.html-product-family/) | [Free Support](https://forum.aspose.com/c/html/29) | [Temporary License](https://purchase.aspose.com/temporary-license/)

docs/basic-usage.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Basic Usage of Aspose.HTML for Java
2+
3+
This guide provides practical examples of using **Aspose.HTML for Java** for common tasks like converting HTML to PDF, rendering images, manipulating DOM, and working with MHTML or EPUB files.
4+
5+
## Convert HTML to PDF
6+
7+
Quickly convert HTML, XHTML, or MHTML files to PDF with a single line of code.
8+
9+
```java
10+
import com.aspose.html.HTMLDocument;
11+
import com.aspose.html.saving.PdfSaveOptions;
12+
import com.aspose.html.converters.Converter;
13+
14+
HTMLDocument document = new HTMLDocument("document.html");
15+
PDFSaveOptions options = new PdfSaveOptions();
16+
Converter.convertHTML(document, options, "output.pdf");
17+
```
18+
19+
## Convert HTML to Image
20+
21+
Render HTML pages as images in PNG, JPEG, BMP, GIF or TIFF formats.
22+
23+
```java
24+
import com.aspose.html.HTMLDocument;
25+
import com.aspose.html.saving.ImageSaveOptions;
26+
import com.aspose.html.saving.SaveFormat;
27+
import com.aspose.html.converters.Converter;
28+
29+
HTMLDocument document = new HTMLDocument("document.html");
30+
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);
31+
Converter.convertHTML(document, options, "output.jpg");
32+
```
33+
34+
## Create an HTML document
35+
36+
```java
37+
import com.aspose.html.HTMLDocument;
38+
import com.aspose.html.dom.Text;
39+
40+
HTMLDocument document = new HTMLDocument();
41+
Text text = document.createTextNode("Hello, World!");
42+
document.getBody().appendChild(text);
43+
document.save($o("create-new-document.html"));
44+
```
45+
46+
## Navigate the HTML DOM
47+
48+
```java
49+
import com.aspose.html.HTMLDocument;
50+
import com.aspose.html.dom.Element;
51+
52+
String html_code = "<span>Hello,</span> <span>World!</span>";
53+
HTMLDocument document = new HTMLDocument(html_code, ".");
54+
Element element = document.getBody().getFirstElementChild();
55+
System.out.println(element.getTextContent());
56+
// @output: Hello,
57+
58+
element = element.getNextElementSibling();
59+
System.out.println(element.getTextContent());
60+
// @output: World!
61+
```
62+
63+
## Load and Convert MHTML to PDF
64+
65+
```java
66+
import com.aspose.html.converters.Converter;
67+
import com.aspose.html.saving.PdfSaveOptions;
68+
69+
java.io.FileInputStream fileInputStream = new java.io.FileInputStream($i("sample.mht"));
70+
PdfSaveOptions options = new PdfSaveOptions();
71+
Converter.convertMHTML(fileInputStream, options, $o("sample-output.pdf"));
72+
```
73+
74+
For complete examples, visit the `Aspose.HTML-for-Java.Example` module in this repository.
75+
76+
## Notes
77+
78+
- You can combine conversion and DOM manipulation in a single workflow.
79+
- All examples can be adapted for SVG, EPUB, Markdown rendering & conversion, or custom save options.
80+
- Refer to the [official Aspose.HTML documentation](https://docs.aspose.com/html/java/) for advanced settings, page layouts, and rendering configuration.

docs/installation.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Aspose.HTML for Java – Installation
2+
3+
This guide explains how to install Aspose.HTML for Java using Maven, Gradle, or by downloading the library manually. Choose the method that best fits your project setup.
4+
5+
## Install via Maven
6+
7+
Add the Aspose repository and dependency to your `pom.xml`:
8+
9+
```xml
10+
<repositories>
11+
<repository>
12+
<id>snapshots</id>
13+
<name>repo</name>
14+
<url>http://repository.aspose.com/repo/</url>
15+
</repository>
16+
</repositories>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.aspose</groupId>
21+
<artifactId>aspose-html</artifactId>
22+
<version>25.12</version>
23+
<classifier>jdk16</classifier>
24+
</dependency>
25+
</dependencies>
26+
```
27+
28+
## Install via Gradle
29+
30+
Add the repository and dependency to your `build.gradle`:
31+
```
32+
repositories {
33+
maven {
34+
url = uri('https://repository.aspose.com/repo/')
35+
}
36+
}
37+
38+
dependencies {
39+
implementation "com.aspose:aspose-html:25.12"
40+
}
41+
```
42+
43+
After completing these steps, the Aspose.HTML for Java library will be successfully configured in your Maven project. You can now begin using its powerful features for HTML manipulation, conversion, and processing.

docs/supported-features.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Aspose.HTML for Java – Supported Features
2+
3+
Aspose.HTML for Java offers powerful tools for working with HTML, SVG, EPUB, and other web formats. Below is a concise overview of the key capabilities.
4+
5+
## Document Manipulation
6+
7+
* **Create and modify web documents.** Load or create HTML, XHTML, SVG, and Markdown files. Open and convert EPUB and MHTML documents with full support for their internal structure and linked resources.
8+
* **Full DOM control.** Insert, edit, clone, replace, or remove elements and attributes at any level.
9+
* **Navigate and inspect documents.** Use DOM traversal APIs to move through nodes and retrieve structured data.
10+
* **Environment configuration.** Apply custom stylesheets, font folders, sandbox rules, and resource handlers.
11+
* **Save with resources.** Export documents along with linked CSS, fonts, scripts, and images.
12+
13+
## Data Extraction
14+
15+
* **Flexible navigation.** Use DOM traversal, XPath, CSS selectors, or JavaScript to locate content.
16+
* **Extract styling and metadata.** Retrieve CSS rules, inline styles, attributes, and other element-level information.
17+
* **Content extraction.** Read and extract text, links, tables, forms, images, and any embedded data with precision.
18+
19+
## Conversion & Rendering
20+
21+
* **One-line conversion.** Convert HTML, XHTML, SVG, MHTML, Markdown, or EPUB into PDF, XPS, DOCX, or images (PNG, JPEG, GIF, BMP, TIFF).
22+
* **Advanced settings.** Control page size, resolution, scripting, resource loading, and other rendering parameters.
23+
* **Markdown workflows.** Convert HTML to MD and vice versa for documentation, publishing, or content pipelines.
24+
* **Timeout control.** Limit rendering time to manage performance in server-side applications.
25+
26+
## Merging
27+
28+
* **Combine documents.** Merge multiple HTML, XHTML, MHTML, EPUB, or Markdown files into a single output with consistent layout and preserved resources.
29+
30+
## HTML Templates
31+
32+
* **Data binding.** Inject JSON or XML data into HTML templates to generate dynamic, repeatable documents.
33+
* **Attribute control.** Add, modify, or remove attributes during binding for cleaner, more precise output.
34+
35+
## Web Accessibility
36+
37+
* **WCAG validation.** Analyze documents for accessibility issues using built-in rules.
38+
* **Contrast & ARIA checks.** Verify colors, ARIA attributes, and screen-reader compatibility.
39+
* **Reporting.** Export detailed accessibility reports for further improvements.
40+
41+
## Advanced HTML Features
42+
43+
* **Canvas editing.** Draw shapes, text, and graphics on HTML5 Canvas programmatically.
44+
* **Stream output.** Render results directly to memory streams, cloud storage, or custom pipelines.
45+
* **DOM monitoring.** Track document changes in real time using MutationObserver.
46+
* **Form processing.** Inspect, edit, populate, and submit HTML forms.
47+
* **Extended CSS.** Use `-aspose-` CSS features for enhanced styling and rendering control.

docs/supported-file-formats.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Supported File Formats
2+
3+
Aspose.HTML for Java supports a wide range of file formats for input, output, and rendering.
4+
5+
## Input Formats
6+
7+
You can load and process content from the following formats:
8+
9+
| **Format** | **Description** |
10+
| ---------------- | ----------------------------------------------------------------------- |
11+
| **HTML / XHTML** | Standard web documents, including inline CSS and JavaScript. |
12+
| **MHTML** | Archive format for complete web pages (HTML + resources). |
13+
| **SVG** | Scalable Vector Graphics, fully supported for rendering and conversion. |
14+
| **Markdown** | Lightweight markup, convertible to HTML and other formats. |
15+
| **EPUB** | Electronic publication format, supported for conversion to HTML or PDF. |
16+
17+
## Output Formats
18+
19+
Aspose.HTML for Java allows you to convert and save content in multiple formats:
20+
21+
| **Format** | **Description** |
22+
| ---------------- | --------------------------------------------------------------------------------------- |
23+
| **PDF** | High-quality, layout-preserving PDF generation. |
24+
| **XPS** | Fixed-layout document format, alternative to PDF. |
25+
| **DOCX** | Microsoft Word document format. |
26+
| **HTML/XHTML** | Save modified or generated HTML content. |
27+
| **Markdown** | Convert HTML or MHTML to Markdown for content migration. |
28+
| **Images** | PNG, JPEG, BMP, GIF, TIFF, WebP. Supports rendering HTML/SVG snapshots or page content. |
29+
30+
31+
For detailed usage examples, see the examples in this repository and the [official Aspose.HTML documentation](https://docs.aspose.com/html/java/)

0 commit comments

Comments
 (0)