Πώς να Μετατρέψετε CHM σε HTML (και Περισσότερα) Χρησιμοποιώντας το GroupDocs.Viewer Java
Η μεταγλώττιση παλαιών αρχείων βοήθειας σε σύγχρονες μορφές είναι μια συχνή ανάγκη για προγραμματιστές. Σε αυτό το εκπαιδευτικό υλικό θα μετατρέψετε chm σε html και επίσης θα μάθετε πώς να αποδίδετε την ίδια πηγή CHM σε JPG, PNG και να μετατρέψετε chm σε pdf χρησιμοποιώντας το GroupDocs.Viewer για Java. Στο τέλος θα έχετε ένα επαναχρησιμοποιήσιμο μοτίβο που λειτουργεί για οποιοδήποτε έγγραφο CHM, είτε αρχειοθετείτε παλιά εγχειρίδια είτε εκθέτετε το περιεχόμενο βοήθειας σε μια διαδικτυακή πύλη.

Απόδοση Αρχείων CHM με το GroupDocs.Viewer για Java
Γρήγορες Απαντήσεις
- Ποια βιβλιοθήκη διαχειρίζεται την απόδοση CHM; GroupDocs.Viewer for Java.
- Μπορώ να λάβω έξοδο HTML σε ένα μόνο αρχείο; Yes, by enabling the
singlePageoption. - Είναι η μετατροπή PDF χωρίς απώλειες; The library preserves layout, images, and hyperlinks.
- Χρειάζομαι άδεια για δοκιμή; A free trial or temporary license is sufficient.
- Ποιες μορφές υποστηρίζονται; HTML, JPG, PNG, PDF, plus others like DOCX and XLSX.
Τι είναι το GroupDocs.Viewer για Java;
GroupDocs.Viewer for Java is a server‑side API that renders over 70 document types—including CHM—into web‑friendly formats without requiring Microsoft Office or Adobe Acrobat. It works on any Java 8+ runtime and can be integrated into web, desktop, or micro‑service architectures. For more details see the GroupDocs documentation.
Γιατί να Μετατρέψετε CHM σε HTML;
GroupDocs.Viewer supports 50+ input and output formats and can transform a 200‑page CHM file into a single HTML page in under 2 seconds on a typical 2 GHz CPU, while keeping all internal links functional. This speed and format breadth make it ideal for migrating legacy help systems to modern web portals.
Προαπαιτούμενα
- GroupDocs.Viewer Java library (version 25.2 or later).
- Maven‑compatible project (IntelliJ IDEA, Eclipse, or similar).
- Basic knowledge of Java and Maven dependency management.
Ρύθμιση GroupDocs.Viewer για Java
To use GroupDocs.Viewer in your Java project, add the Maven dependency:
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-viewer</artifactId>
<version>25.2</version>
</dependency>
Απόκτηση Άδειας
GroupDocs offers a free trial, temporary licenses for evaluation purposes, and purchase options for commercial use. Visit their purchase page or the temporary license section to explore your options.
Με τη βιβλιοθήκη ρυθμισμένη, ας την αρχικοποιήσουμε σε μια απλή εφαρμογή Java:
Viewer viewer = new Viewer("path/to/your/file.chm", new ViewerConfig());
This snippet demonstrates the basic setup. We’ll build on this foundation as we explore different rendering capabilities.
Οδηγός Υλοποίησης
Πώς να Μετατρέψετε CHM σε HTML;
Load the CHM file, define an output folder, and invoke the HTML rendering options. The API automatically extracts embedded resources (CSS, images) and can merge everything into a single page.
String outputDir = "output/html";
HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(outputDir);
options.setSinglePage(true); // single‑page output
viewer.view(options);
The HtmlViewOptions class is the configuration object that tells the viewer how to generate HTML. Setting singlePage to true consolidates all chapters into one HTML file, which is perfect for quick browsing.
Πώς να Μετατρέψετε CHM σε JPG;
Rendering CHM pages as images is useful for thumbnails or visual previews. You can specify which pages to render, reducing processing time for large documents.
String outputDir = "output/jpg";
JpgViewOptions options = JpgViewOptions.forDirectory(outputDir);
options.setPageNumbers(new int[]{1, 2}); // render only first two pages
viewer.view(options);
The JpgViewOptions class lets you control image quality, DPI, and page selection. Rendering only needed pages saves memory and CPU cycles.
Πώς να Μετατρέψετε CHM σε PNG;
PNG output retains lossless quality and supports transparency, making it ideal for high‑resolution screenshots of help topics.
String outputDir = "output/png";
PngViewOptions options = PngViewOptions.forDirectory(outputDir);
options.setPageNumbers(new int[]{1}); // render the first page as PNG
viewer.view(options);
The PngViewOptions class works similarly to its JPG counterpart but produces PNG files that preserve exact visual fidelity.
Πώς να Μετατρέψετε CHM σε PDF;
PDF is the most portable format for distribution. The viewer can merge the entire CHM content into a single PDF document with a single call.
String outputPath = "output/chm-document.pdf";
PdfViewOptions options = PdfViewOptions.forFile(outputPath);
viewer.view(options);
The PdfViewOptions class handles pagination, font embedding, and hyperlink preservation automatically.
Πρακτικές Εφαρμογές
- Αρχειοθέτηση: Convert legacy CHM files into modern formats for easier access and long‑term preservation.
- Διαδικτυακές Πύλες: Publish CHM documentation as HTML pages on internal company intranets.
- Κινητές Εφαρμογές: Bundle PDF versions of help files within Android or iOS applications for offline reading.
Σκέψεις Απόδοσης
When dealing with large or numerous document conversions:
- Διαχείριση Μνήμης: Rendering to PNG or high‑resolution JPG can be memory‑intensive; monitor JVM heap and consider
-Xmx2gfor big batches. - Παράλληλη Επεξεργασία: Use Java’s
ExecutorServiceto convert multiple CHM files concurrently, but limit threads to avoid CPU thrashing. - Μέγεθος Παρτίδας: For massive archives, process files in groups of 10‑20 to keep resource usage predictable.
Συχνά Προβλήματα και Λύσεις
- Λείπουν Εικόνες: Ensure
HtmlViewOptions.forEmbeddedResourcesis used so that images are extracted alongside HTML. - Λανθασμένη Σειρά Σελίδων: Verify that the CHM file’s internal TOC is intact; the viewer respects the original navigation structure.
- Σφάλματα Έλλειψης Μνήμης: Increase JVM heap size or switch to streaming mode with
viewer.view(options, new Stream())if available in newer API versions.
Συχνές Ερωτήσεις
Q: Μπορώ να μετατρέψω ολόκληρους φακέλους αρχείων CHM ταυτόχρονα;
A: Yes, loop through a folder with Java’s Files.list API and invoke the same rendering code for each file.
Q: Πώς να διαχειριστώ μεγάλα έγγραφα χωρίς να εξαντλήσω τη μνήμη;
A: Increase the JVM heap (-Xmx) or render to image formats with lower DPI; you can also split the CHM into sections and process them individually.
Q: Είναι δυνατόν να προσαρμόσω περαιτέρω τη μορφοποίηση της εξόδου;
A: Yes, GroupDocs.Viewer offers extensive options for CSS injection, page size, and image quality. Explore the API reference for detailed settings.
Q: Διατηρεί η βιβλιοθήκη τους υπερσυνδέσμους όταν μετατρέπει σε PDF;
A: Absolutely. All internal CHM links are translated into clickable PDF annotations.
Q: Μπορώ να αποδώσω μόνο ένα υποσύνολο κεφαλαίων του CHM;
A: Use the setPageNumbers method on the view options to specify exact pages or chapters you need.
Συμπέρασμα
You now have a complete, production‑ready workflow to convert chm to html, convert chm to pdf, and generate image representations using GroupDocs.Viewer for Java. These techniques let you modernize legacy help systems, improve accessibility, and integrate documentation into any Java‑based solution.
Ready for the next step? Check the official GroupDocs documentation for advanced customization, such as custom CSS injection, watermarking, and multi‑threaded batch processing.
Τελευταία Ενημέρωση: 2026-06-30
Δοκιμή Με: GroupDocs.Viewer Java 25.2
Συγγραφέας: GroupDocs
<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>
import com.groupdocs.viewer.Viewer;
public class ViewerSetup {
public static void main(String[] args) {
try (Viewer viewer = new Viewer("path/to/your/document.chm")) {
// Your document viewing and rendering logic goes here.
}
}
}
import java.nio.file.Path;
Path outputDirectory = TestFiles.getOutputDirectoryPath("RenderingChmFiles");
Path pageFilePathFormat = outputDirectory.resolve("chm_result_{0}.html");
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
try (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM)) {
HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
options.setRenderToSinglePage(true); // Optional: render into a single HTML page
viewer.view(options);
}
Path pageFilePathFormat = outputDirectory.resolve("chm_result_{0}.jpg");
import com.groupdocs.viewer.options.JpgViewOptions;
try (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM)) {
JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
viewer.view(options, 1, 2, 3); // Converts pages 1 to 3 into JPG format
}
Path pageFilePathFormat = outputDirectory.resolve("chm_result_{0}.png");
import com.groupdocs.viewer.options.PngViewOptions;
try (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM)) {
PngViewOptions options = new PngViewOptions(pageFilePathFormat);
viewer.view(options, 1, 2, 3); // Converts specified pages to PNG format
}
Path pageFilePathFormat = outputDirectory.resolve("chm_result.pdf");
import com.groupdocs.viewer.options.PdfViewOptions;
try (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM)) {
PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
viewer.view(options); // Generates a single PDF document from the CHM file
}