Convert zip to html and set items per page with GroupDocs.Viewer Java

In many web applications you need to show the contents of a ZIP or RAR archive directly in a browser. How to convert zip files into HTML using GroupDocs.Viewer for Java is a common requirement, and the library lets you embed images, CSS, and fonts so the result is a single, portable page. This tutorial walks you through everything—from Maven setup to multi‑page rendering—while explaining why each option matters for performance and usability.

Convert Archives to HTML with GroupDocs.Viewer for Java

Quick answers

  • What does “set items per page” control? It determines how many files or folders from an archive appear on each generated HTML page.
  • Can I embed images and CSS directly in the HTML? Yes – use the forEmbeddedResources option to embed resources HTML.
  • Is batch conversion possible? Absolutely; you can loop over a collection of archives and render each one with the same settings.
  • Do I need Maven to use GroupDocs.Viewer? Yes, add the groupdocs-viewer Maven dependency as shown below.
  • Which output formats are supported? Single‑page HTML and multi‑page HTML are both available, and the library supports 50+ input archive types.

What is “set items per page” in GroupDocs.Viewer?

It tells the viewer how many archive entries (files or folders) should be displayed on each HTML page when you generate a multi‑page document. Adjusting this value helps you balance page size and navigation speed, especially for large archives, by limiting the amount of data loaded per page and reducing rendering time for end users.

Why embed resources html?

Embedding resources (images, CSS, fonts) directly inside the HTML file creates a single, portable document that can be opened without external files. This is ideal for email attachments, offline viewing, or embedding the output into other web pages. It also removes the need to manage external asset paths.

Prerequisites

  • Required libraries: Include GroupDocs.Viewer version 25.2 or later.
  • Environment: Java Development Kit (JDK) installed and configured.
  • Knowledge: Basic Java and Maven dependency management.

Maven GroupDocs Viewer setup

Add the GroupDocs repository and the viewer 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

GroupDocs.Viewer offers a free trial link, a temporary license, or a full purchase option. Choose the one that fits your project timeline.

Basic initialization

The Viewer class is the entry point for rendering documents and archives. After the Maven setup, bring the viewer into your code:

import com.groupdocs.viewer.Viewer;
// Your initialization code here

How to render archives to single‑page html

The HtmlViewOptions class defines settings for HTML output, such as embedding resources. Load the archive, configure HTML options to embed resources, and render everything into one self‑contained page. This produces a single HTML file that contains all files, images, CSS, and fonts, ready for offline use or email attachment.

Direct answer: Create a Viewer instance for the ZIP file, call HtmlViewOptions.forEmbeddedResources(), and invoke viewer.view(documentPath, options). This produces a single HTML file that contains all files, images, CSS, and fonts, ready for offline use or email attachment.

Step 1: Define output directory

Path outputDirectory = Utils.getOutputDirectoryPath("YOUR_OUTPUT_DIRECTORY");

Step 2: Set file name for single‑page output

Path pageFilePathFormat = outputDirectory.resolve("RAR_result.html");

Step 3: Initialize the viewer

try (Viewer viewer = new Viewer(TestFiles.SAMPLE_RAR_WITH_FOLDERS)) {
    // Further configuration steps follow
}

Step 4: Configure rendering options (embed resources html)

The HtmlViewOptions class defines settings for HTML output, such as embedding resources. Use forEmbeddedResources() to bundle everything into one file.

HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);

Step 5: Render as a single page

options.setRenderToSinglePage(true);
viewer.view(options);

How to render archives to multi‑page html and set items per page

The HtmlViewOptions class also supports pagination. By calling options.setItemsPerPage(N), you instruct the viewer to split the archive into several HTML files, each showing up to N entries. This approach improves navigation speed for large archives while keeping each page lightweight.

Direct answer: Use HtmlViewOptions.forEmbeddedResources(), call options.setItemsPerPage(N), and render the archive. The viewer will generate separate HTML files—one per page—each containing up to N entries, which speeds up navigation for big archives.

Step 1: Reuse the output directory

Path outputDirectory = Utils.getOutputDirectoryPath("YOUR_OUTPUT_DIRECTORY");

Step 2: Define file name format for multiple pages

Path pageFilePathFormat = outputDirectory.resolve("RAR_result_page_{0}.html");

Step 3: Initialize the viewer again

try (Viewer viewer = new Viewer(TestFiles.SAMPLE_RAR_WITH_FOLDERS)) {
    // Continue with multi‑page configuration
}

Step 4: Configure multi‑page options (embed resources html)

HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);

Step 5: Set items per page (primary keyword in action)

options.setItemsPerPage(20); // how to convert zip archives with 20 entries per page

options.getArchiveOptions().setItemsPerPage(10); // Default is 16
viewer.view(options);

Practical applications

  • Document management systems: Add archive preview functionality without installing extra viewers.
  • Web portals: Offer users a quick, no‑download way to explore bundled documents.
  • Collaboration tools: Let teams inspect shared archives directly in the browser.

Performance considerations

  • Resource management: Keep memory usage low by processing archives in streams; the viewer can handle archives up to 500 MB without loading the entire file into memory.
  • Batch convert archives: Loop through a list of archive files and call the same rendering logic to maximize throughput.
  • Caching strategy: Store rendered HTML in a cache if the same archive is accessed frequently, reducing repeat processing time by up to 70 %.

Frequently asked questions

Q: What is GroupDocs.Viewer Java?
A: GroupDocs.Viewer Java is a server‑side library that renders over 50 document and archive formats—including ZIP and RAR—into HTML, PDF, or image files without requiring external applications.

Q: How can I obtain a free trial of GroupDocs.Viewer?
A: Visit the free trial link to download and test.

Q: Can I convert other document types besides archives?
A: Yes, the viewer supports PDFs, Word, Excel, PowerPoint, and 35+ additional formats.

Q: What should I do if rendering is slow?
A: Reduce the number of items per page, enable streaming, or process archives in smaller batches to improve speed.

Q: Where can I get help or support?
A: Reach out via the support forum.

Q: Is it possible to embed CSS and images directly in the HTML?
A: Absolutely—use HtmlViewOptions.forEmbeddedResources as shown in the examples.

Q: How do I batch convert a folder of archives?
A: Iterate over each file with a for loop, applying the same Viewer and HtmlViewOptions configuration for each iteration.

Q: Where can I discuss issues with other users?
A: Visit the GroupDocs forum for community discussions.

Resources


Last Updated: 2026-10-10
Tested With: GroupDocs.Viewer 25.2
Author: GroupDocs