Render archives as HTML, PDF, and image files
Leave feedback
On this page
GroupDocs.Viewer for Node.js via Java allows you to view the contents of archive files in HTML, PDF, PNG, and JPEG formats. You do not need to use third-party file archiver and compression software to display archive file contents within your Node.js application (web or desktop).
To start using the GroupDocs.Viewer API, create a Viewer class instance. Pass an archive file you want to view to the class constructor. You can load the archive from a file or stream. Call one of the Viewer.view method overloads to convert the archive file to HTML, PDF, or image format.
import{Viewer,HtmlViewOptions}from'@groupdocs/groupdocs.viewer';constviewer=newViewer("documents.zip")// Create an HTML file for top folder and each subfolder in the archive.
// {0} is replaced with the current page number in the file name.
constviewOptions=HtmlViewOptions.forEmbeddedResources("render-archive-to-html/zip-to-html-page_{0}.html")viewer.view(viewOptions)
documents.zip is the sample file used in this example. Click here to download it.
import{Viewer,HtmlViewOptions}from'@groupdocs/groupdocs.viewer';constviewer=newViewer("documents.zip")// Create an HTML file for the top folder and each subfolder in the archive.
// {0} is replaced with the current page number in the output file name.
constviewOptions=HtmlViewOptions.forEmbeddedResources("render-archive-to-single-page/zip-to-html-page_{0}.html")// Specify the number of items to display on each HTML page.
viewOptions.setRenderToSinglePage(true)viewer.view(viewOptions)
documents.zip is the sample file used in this example. Click here to download it.
The animation below demonstrates the result. You can navigate between the archive folders. Click on a particular folder to see its contents. To go backward, click the required folder name in the navigation bar at the top of the web page.
Render archive files as PDF
Create a PdfViewOptions class instance and pass it to the Viewer.view method to convert an archive file to PDF. The PdfViewOptions class properties allow you to control the conversion process. For instance, you can protect the output PDF file or reorder its pages. Refer to the following documentation section for details: Rendering to PDF.
import{Viewer,PdfViewOptions}from'@groupdocs/groupdocs.viewer';constviewer=newViewer("documents.zip")// Specify the PDF file name.
constviewOptions=PdfViewOptions("render-archive-to-pdf/zip-to-pdf.pdf")viewer.view(viewOptions)
documents.zip is the sample file used in this example. Click here to download it.
import{Viewer,PngViewOptions}from'@groupdocs/groupdocs.viewer';constviewer=newViewer("documents.zip")// Create a PNG image for the top folder and each subfolder in the archive.
// {0} is replaced with the current page number in the image name.
constviewOptions=PngViewOptions("render-archive-to-png/zip-to-png-page_{0}.png")// Set width and height.
viewOptions.setWidth(950)viewOptions.setHeight(550)viewer.view(viewOptions)
documents.zip is the sample file used in this example. Click here to download it.
import{Viewer,JpgViewOptions}from'@groupdocs/groupdocs.viewer';constviewer=newViewer("documents.zip")// Create a JPG image for the top folder and each subfolder in the archive.
// {0} is replaced with the current page number in the image name.
constviewOptions=JpgViewOptions("render-archive-to-jpeg/zip-to-jpg-page_{0}.jpg")// Set width and height.
viewOptions.setWidth(950)viewOptions.setHeight(550)viewer.view(viewOptions)
documents.zip is the sample file used in this example. Click here to download it.
Obtain information about folders in an archive file
Call the Viewer.getViewInfo method, pass the ViewInfoOptions instance to this method as a parameter, and cast the returned object to the ArchiveViewInfo type.
When you convert an archive file to HTML, PDF, or image format, GroupDocs.Viewer renders items from all folders contained in the archive. If you need to render items from a specific folder, use the ArchiveOptions.setFolder method of one of the following classes (depending on the output file format):
documents.zip is the sample file used in this example. Click here to download it.
Specify the archive file name
When rendering an archive file, GroupDocs.Viewer displays the archive file name in the header of each page. If you need to change or hide this name, use the ArchiveOptions.setFileName method for a target view. You can set this option to one of the following values:
FileName.SOURCE— Returns the name of the source file (this name is used by default).
FileName.EMPTY—Specifies an empty name. Use this value to hide the archive file name in the output file.
A FileName instance with a custom name you want to display in the output file.
The following code snippet demonstrates how to use a custom name when rendering an archive file to HTML: