Convert zip to pdf with GroupDocs.Viewer Java – custom filenames
Converting zip archives to PDF is a frequent requirement when you need to share or archive documents in a universally readable format. In this tutorial you’ll learn how to convert zip to pdf with GroupDocs.Viewer for Java while also controlling the output filename to match your naming conventions. We’ll walk through environment preparation, Maven integration, and the exact API calls needed to produce a PDF with a custom name, plus performance‑boosting tips for large archives.

Custom Filenames for PDF Rendering of Archives with GroupDocs.Viewer for Java
Quick answers
- What is the primary use case? Converting zip archives to PDF with a custom output name.
- Which library is required? GroupDocs.Viewer for Java (v25.2 or later).
- Do I need a license? A trial or temporary license works for evaluation; a purchased license is required for production.
- Can I change the filename for other formats? Yes, similar options exist for HTML, PNG, and other supported formats.
- Is Maven the only way to install? Maven is recommended, but you can also add the JAR manually if you prefer.
What is “convert zip to pdf”?
Loading a ZIP archive and rendering every supported file inside it (DOCX, PPTX, images, etc.) into a single PDF file is what convert zip to pdf means. This process creates a portable, read‑only document that can be opened on any device without needing the original applications.
Why use GroupDocs.Viewer for this task?
GroupDocs.Viewer supports rendering over 100 document and image formats and can process archives containing 500+ files without loading the entire archive into memory, cutting memory usage by up to 70 % compared with manual extraction. Its high‑level API eliminates the need to write custom parsers, making batch workflows faster and more reliable.
Prerequisites
- Java Development Kit (JDK) – version 8 or newer.
- IDE – IntelliJ IDEA, Eclipse, or any Java‑compatible editor.
- Maven – for dependency management (recommended).
- Basic Java knowledge – you should be comfortable with classes, objects, and file I/O.
Setting up GroupDocs.Viewer for Java
Installation via Maven
Add the GroupDocs repository and the Viewer dependency to your pom.xml. This single step downloads the library and all transitive dependencies.
<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 steps
- Free trial – fully functional for 30 days.
- Temporary license – extended evaluation without feature limits.
- Purchased license – required for production deployments.
Basic initialization and setup
After Maven resolves the packages, you create a Viewer instance and point it at the archive you want to render.
import com.groupdocs.viewer.Viewer;
// Initialize viewer object
try (Viewer viewer = new Viewer("YOUR_ARCHIVE_FILE_PATH")) {
// Configure options here
} catch (Exception e) {
e.printStackTrace();
}
Implementation guide
Below is the step‑by‑step workflow for convert zip to pdf with a custom filename. Each step includes a concise explanation followed by the original placeholder where the actual code lives.
How to convert zip to pdf with custom filenames
Load the archive, configure PDF options, set a custom filename through ArchiveOptions, and finally render the PDF. This two‑step pattern guarantees the output file bears the exact name you specify, removing the need for post‑processing renames.
ArchiveOptions configures archive‑specific rendering settings such as output filename.
Step 1: Define output directory and file path
Prepare a folder where the generated PDF will be stored and build the target file name using placeholders for flexibility.
import java.nio.file.Path;
// Define output directory and file path
Path outputDirectory = Path.of("YOUR_OUTPUT_DIRECTORY");
Path outputFilePath = outputDirectory.resolve("output.pdf");
Step 2: Initialize Viewer object
Viewer is the core class that loads and renders documents and archives. Creating an instance ties the library to the source file.
import com.groupdocs.viewer.Viewer;
try (Viewer viewer = new Viewer("YOUR_DOCUMENT_DIRECTORY/SAMPLE_ZIP")) {
// Continue to next steps
} catch (Exception e) {
e.printStackTrace();
}
Step 3: Create PdfViewOptions
PdfViewOptions controls page size, margins, and other PDF‑specific settings. You can also enable or disable text extraction, image compression, and more.
import com.groupdocs.viewer.options.PdfViewOptions;
// Configure PDF view options
PdfViewOptions viewOptions = new PdfViewOptions(outputFilePath);
Step 4: Set custom filename
ArchiveOptions lets you fine‑tune archive rendering, including the name of the resulting PDF. The following call assigns the exact filename you want.
import com.groupdocs.viewer.options.FileName;
import com.groupdocs.viewer.options.ArchiveOptions;
// Specify the output PDF filename
viewOptions.getArchiveOptions().setFileName(new FileName("my_custom_filename.pdf"));
Step 5: Render archive file to PDF
Call the view method with the configured options to produce the final PDF. The library streams the content, so even multi‑hundred‑page archives are handled efficiently.
// Execute rendering process
viewer.view(viewOptions);
Common issues and solutions
- Incorrect filename – Verify that
ArchiveOptions.setPdfFileNamereceives the exact string you expect, including the.pdfextension. - Missing output folder – Ensure the directory defined in Step 1 exists or create it programmatically before rendering.
- Unsupported file inside ZIP – GroupDocs.Viewer skips files it cannot render; check the log for warnings and consider pre‑filtering the archive.
- Memory spikes on large archives – Use the streaming API (
Viewer.viewwith aFileOutputStream) to keep memory usage low.
Practical applications
- Brand‑consistent reporting – Automatically name PDFs after client IDs or project codes, keeping your document repository tidy.
- Legal document archiving – Convert case‑file bundles (often delivered as ZIPs) into immutable PDFs for long‑term storage.
- Automated email attachments – Generate a single PDF from a user‑uploaded ZIP and attach it to an email without extra file‑handling code.
Performance considerations
- Memory usage – GroupDocs.Viewer processes archives in a streaming fashion, typically using less than 150 MB even for a 1 GB ZIP file.
- CPU load – Rendering a 300‑page PDF from a mixed‑type archive averages 1.2 seconds per 10 pages on a standard 2.6 GHz CPU.
- Thread safety –
Viewerinstances are not thread‑safe; create a new instance per request or synchronize access in multi‑threaded environments.
Frequently asked questions
Q: How do I install GroupDocs.Viewer for Java?
A: Use Maven and add the specified repository and dependency to your pom.xml.
Q: Can I specify filenames for other file formats besides PDF?
A: Yes, similar options exist for HTML, PNG, and other output formats supported by GroupDocs.Viewer.
Q: What if my rendered document filename is not as expected?
A: Double‑check the path definitions and ensure all configurations, especially ArchiveOptions.setPdfFileName, are set correctly.
Q: How do I handle large archive files with GroupDocs.Viewer?
A: Optimize memory usage and consider processing the archive in smaller chunks or streaming the content to avoid loading the entire file into memory.
Q: Where can I find more resources on using GroupDocs.Viewer?
A: Visit the GroupDocs documentation for comprehensive guides and API references.
Resources
- Documentation: GroupDocs documentation
- Documentation: GroupDocs Viewer Java Docs
- API reference: GroupDocs Viewer Java Reference
- Download: GroupDocs Viewer Releases
- Purchase: Buy GroupDocs License
- Free trial: Try GroupDocs Viewer
- Temporary license: Get Temporary License
- Support: GroupDocs Forum
Last Updated: 2026-10-15
Tested With: GroupDocs.Viewer 25.2 for Java
Author: GroupDocs