|
| 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/) |
0 commit comments