Generate html from pdf and disable grouping with GroupDocs Viewer for Java
In many projects you need to generate html from pdf while keeping every glyph exactly where it belongs. This is especially true for complex scripts, ancient languages, or legal documents where a single misplaced character can change meaning. In this tutorial we’ll walk you through the complete process of rendering PDFs to HTML with GroupDocs Viewer for Java and show you how to disable grouping so each character is treated as an independent element.

Quick answers
- What does “disable grouping” do? It forces the renderer to treat each character as an independent element, preserving exact layout.
- Which API option controls this?
viewOptions.getPdfOptions().setDisableCharsGrouping(true). - Do I need a license? A trial works for testing, but a full license is required for production.
- Can I generate html from pdf at the same time? Yes—use
HtmlViewOptionsto create HTML output while disabling grouping. - Is this feature limited to PDFs? It’s primarily for PDFs, but the viewer supports many other formats.
What is generate html from pdf?
generate html from pdf describes the process of converting a PDF document into a set of HTML pages that retain the original layout, fonts, and images. This conversion enables easy web‑based viewing, indexing, and interaction without needing a PDF plugin.
Why use GroupDocs Viewer for Java?
GroupDocs.Viewer for Java supports over 100 input formats and can render PDFs up to 500 pages without loading the entire file into memory. The library processes each page in a streaming fashion, which reduces heap usage by up to 70 % compared with full‑document loading. These quantified capabilities make it a reliable choice for high‑volume, enterprise‑grade document pipelines.
Introduction
When working with PDF documents, precision in rendering is crucial—especially when dealing with complex text structures like hieroglyphics or languages that require precise character representation. The “Character Grouping” feature often causes issues by grouping characters incorrectly, leading to misinterpretation of the document content. This can be particularly problematic for users needing exact replication of their documents’ text layout.
GroupDocs.Viewer for Java is a server‑side library that renders over 100 document formats to HTML, images, and PDF, providing pixel‑perfect fidelity.
Prerequisites
Before diving into code implementation, ensure that you meet the following requirements:
- Libraries & dependencies: You’ll need GroupDocs.Viewer for Java version 25.2 or later.
- Environment setup: Install a Java Development Kit (JDK) and configure your IDE for Maven projects.
- Knowledge prerequisites: Basic Java programming, file‑system handling, and familiarity with Maven.
How to generate html from pdf with GroupDocs Viewer
Generating html from pdf is a two‑step process: configure the viewer, then render the document. The key is to turn off character grouping before rendering so the HTML output mirrors the original PDF layout character‑by‑character.
Setting up GroupDocs.Viewer for Java
Installation via Maven
Add the following dependency to your pom.xml:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/viewer/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-viewer</artifactId>
<version>25.2</version>
</dependency>
</dependencies>
License acquisition
To fully utilize GroupDocs.Viewer, consider acquiring a license:
- Free trial: Start with the free trial to test features.
- Temporary license: Apply for a temporary license if you need more time.
- Purchase: For long‑term projects, purchasing a license is advisable.
Basic initialization and setup
HtmlViewOptions configures the output format and options for rendering a document to HTML.
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
import java.nio.file.Path;
// Initialize the GroupDocs Viewer
Path outputDirectory = Utils.getOutputDirectoryPath("DisableCharactersGrouping");
Path pageFilePathFormat = outputDirectory.resolve("page_{0}.html");
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
viewOptions.getPdfOptions().setDisableCharsGrouping(true);
try (Viewer viewer = new Viewer("YOUR_DOCUMENT_DIRECTORY/HIEROGLYPHS_PDF")) {
viewer.view(viewOptions);
}
Implementation guide
Feature: disable characters grouping
Below we break down each line of the example so you can understand why we do it and how it contributes to generating html from pdf without unwanted character merging.
Step 1: define output directory
Path outputDirectory = Utils.getOutputDirectoryPath("DisableCharactersGrouping");
Why? This ensures your rendered HTML files are stored in a dedicated folder, making it easy to locate and manage them later.
Step 2: configure file path format
Path pageFilePathFormat = outputDirectory.resolve("page_{0}.html");
Why? Using a placeholder ({0}) lets the viewer create a separate HTML file for each PDF page, keeping the output organized.
Step 3: initialize HTML view options
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
Why? Embedded resources bundle images, fonts, and CSS directly with each HTML page, which is ideal for web‑based viewers or e‑learning platforms.
Step 4: disable character grouping
setDisableCharsGrouping(true) disables the default behavior of grouping adjacent characters, ensuring each glyph is rendered separately.
viewOptions.getPdfOptions().setDisableCharsGrouping(true);
Why? This is the crucial line that tells the rendering engine not to merge adjacent characters, guaranteeing that the generated HTML reflects the exact glyph placement from the source PDF.
Step 5: render the document
Viewer is the primary class that opens a document and provides rendering capabilities.
try (Viewer viewer = new Viewer("YOUR_DOCUMENT_DIRECTORY/HIEROGLYPHS_PDF")) {
viewer.view(viewOptions);
}
Why? Wrapping the Viewer in a try‑with‑resources block guarantees that all native resources are released automatically, preventing memory leaks in long‑running applications.
How does disabling character grouping improve HTML fidelity?
Disabling character grouping forces the engine to output each glyph as a separate HTML element, which preserves the original spacing, ligatures, and diacritics exactly as they appear in the source PDF. This results in a faithful web representation that is essential for scripts where character order and spacing convey meaning, such as Arabic, Devanagari, or ancient hieroglyphic texts.
What are the performance implications of disabling grouping?
Turning off grouping slightly increases CPU cycles because the renderer processes every character individually. In practice, the overhead is under 5 % for typical 100‑page PDFs and remains under 12 % for documents exceeding 500 pages, provided the JVM heap is sized appropriately (e.g., -Xmx2g). The trade‑off is worthwhile when exact visual fidelity is required.
Common issues and solutions
- FileNotFoundException – Double‑check the path you pass to
new Viewer(...). Use absolute paths orPath.of(...)for clarity. - Write permissions – Ensure the output directory is writable by the Java process; on Linux you may need to adjust folder permissions (
chmod 775). - Version mismatch – The
setDisableCharsGroupingoption is available starting with version 25.2. Verify yourpom.xmlreflects the correct version.
Practical applications
- Language preservation – Ideal for rendering documents in Chinese, Japanese, Arabic, or ancient scripts where character spacing carries meaning.
- Legal & financial documents – Guarantees exact text replication for compliance‑heavy paperwork.
- Educational resources – Perfect for textbooks that include complex diagrams, annotations, or multilingual content.
Performance considerations
- Optimize resource usage – Large PDFs can consume significant memory. Process pages in batches and dispose of
Viewerinstances promptly. - Java memory management – Tune the JVM heap (
-Xmx2gor higher) if you anticipate processing multi‑hundred‑page PDFs. - Parallel rendering – For bulk conversions, spawn separate threads each with its own
Viewerinstance to leverage multi‑core CPUs.
Frequently asked questions
Q: Why would I need to disable character grouping at all?
A: Disabling grouping prevents the renderer from merging characters that belong to distinct glyphs, which is essential for scripts where spacing and ordering convey meaning.
Q: Is the setDisableCharsGrouping setting applicable to HTML output only?
A: No, it affects the underlying PDF rendering engine, so any output format (HTML, PNG, JPEG, etc.) will reflect the change.
Q: Can I combine this setting with custom fonts?
A: Yes—load your custom fonts before initializing Viewer, and the grouping rule will still apply.
Q: Does disabling grouping impact performance?
A: Slightly, because the engine processes each character individually, but the impact is minimal for most documents (typically under 5 % overhead).
Q: Is there a way to toggle grouping on a per‑page basis?
A: Currently the option is global per PdfOptions instance; you would need separate Viewer instances for different pages if you require mixed behavior.
Resources
- GroupDocs Documentation
- API Reference
- Download GroupDocs Viewer
- Purchase License
- Free Trial Version
- Temporary License Application
- GroupDocs Support Forum
Last Updated: 2026-09-05
Tested With: GroupDocs.Viewer 25.2 for Java
Author: GroupDocs