Render archives as HTML, PDF, and image files (old version)
Render archives as HTML, PDF, and image files (old version)
Leave feedback
On this page
Note
This article explaing working with archives using old versions of the GroupDocs.Viewer for .NET, before the version 24.10 was released. If you’re using GroupDocs.Viewer or newer, please read the main article.
GroupDocs.Viewer for .NET 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 .NET 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.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=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.varviewOptions=HtmlViewOptions.ForEmbeddedResources("page_{0}.html");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=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.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources("page_{0}.html")viewer.View(viewOptions)EndUsingEndSubEndModule
The following image demonstrates the result:
Specify the number of items to render
GroupDocs.Viewer supports the HtmlViewOptions.ArchiveOptions.ItemsPerPage option that allows you to specify the number of archive items to display on each HTML page. The default property value is 16.
The following example demonstrates how to set this option in code:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=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.varviewOptions=HtmlViewOptions.ForEmbeddedResources("page_{0}.html");// Specify the number of items to display on each HTML page.viewOptions.ArchiveOptions.ItemsPerPage=10;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=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.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources("page_{0}.html")' Specify the number of items to display on each HTML page.
viewOptions.ArchiveOptions.ItemsPerPage=10viewer.View(viewOptions)EndUsingEndSubEndModule
Create a single HTML page
If you need to display the contents of an archive file on a single HTML page, enable the HtmlViewOptions.RenderToSinglePage option, as shown below:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("Documents.zip")){// Create an HTML file.varviewOptions=HtmlViewOptions.ForEmbeddedResources("output.html");// Render the archive file to a single page.viewOptions.RenderToSinglePage=true;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("Documents.zip")' Create an HTML file.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources("output.html")' Render the archive file to a single page.
viewOptions.RenderToSinglePage=Trueviewer.View(viewOptions)EndUsingEndSubEndModule
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.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("Documents.zip")){// Create a PDF file.varviewOptions=newPdfViewOptions("output.pdf");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("Documents.zip")' Create a PDF file.
DimviewOptions=NewPdfViewOptions("output.pdf")viewer.View(viewOptions)EndUsingEndSubEndModule
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=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.varviewOptions=newPngViewOptions("output_{0}.png");// Set width and height.viewOptions.Width=800;viewOptions.Height=1000;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=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.
DimviewOptions=NewPngViewOptions("output_{0}.png")' Set width and height.
viewOptions.Width=800viewOptions.Height=1000viewer.View(viewOptions)EndUsingEndSubEndModule
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("Documents.zip")){// Create a JPEG image for the top folder and each subfolder in the archive.// {0} is replaced with the current page number in the image name.varviewOptions=newJpgViewOptions("output_{0}.jpg");// Set width and height.viewOptions.Width=800;viewOptions.Height=1000;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("Documents.zip")' Create a JPEG image for the top folder and each subfolder in the archive.
' {0} is replaced with the current page number in the image name.
DimviewOptions=NewJpgViewOptions("output_{0}.jpg")' Set width and height.
viewOptions.Width=800viewOptions.Height=1000viewer.View(viewOptions)EndUsingEndSubEndModule
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.
Use the ArchiveViewInfo.Folders property to obtain the lists of folders in the archive file.
usingSystem;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;usingGroupDocs.Viewer.Results;// ...using(varviewer=newViewer("Documents.zip")){varviewInfoOptions=ViewInfoOptions.ForHtmlView();varviewInfo=viewer.GetViewInfo(viewInfoOptions)asArchiveViewInfo;if(viewInfo!=null){Console.WriteLine($"File type: {viewInfo.FileType}");Console.WriteLine($"The number of pages: {viewInfo.Pages.Count}");Console.WriteLine("Folders: ");// Display the list of folders in the archive file.foreach(stringfolderinviewInfo.Folders)Console.WriteLine($" - {folder}");}}
ImportsSystemImportsGroupDocs.ViewerImportsGroupDocs.Viewer.OptionsImportsGroupDocs.Viewer.Results' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("Documents.zip")DimviewInfoOptions=ViewInfoOptions.ForHtmlView()DimviewInfo=TryCast(viewer.GetViewInfo(viewInfoOptions),ArchiveViewInfo)IfviewInfoIsNotNothingThenConsole.WriteLine($"File type: {viewInfo.FileType}")Console.WriteLine($"The number of pages: {viewInfo.Pages.Count}")Console.WriteLine("Folders: ")' Display the list of folders in the archive file.
ForEachfolderAsStringInviewInfo.FoldersConsole.WriteLine($" - {folder}")NextEndIfEndUsingEndSubEndModule
The following image shows a sample console output:
GroupDocs.Viewer also allows you to list and extract all files contained in the archive. Refer to the following help topics for details:
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, specify the ArchiveOptions.Folder property for one of the following classes (depending on the output file format):
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("Documents.zip")){// Create an HTML file.varviewOptions=HtmlViewOptions.ForEmbeddedResources("output.html");// Specify a folder to render items from.viewOptions.ArchiveOptions.Folder="Documents/CAD files";viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("Documents.zip")' Create an HTML file.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources("output.html")' Specify a folder to render items from.
viewOptions.ArchiveOptions.Folder="Documents/CAD files"viewer.View(viewOptions)EndUsingEndSubEndModule
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, define the ArchiveOptions.FileName property 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:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=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.varviewOptions=HtmlViewOptions.ForEmbeddedResources("page_{0}.html");// Specify a custom filenameviewOptions.ArchiveOptions.FileName=newFileName("Sample Files");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=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.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources("page_{0}.html")' Specify a custom filename
viewOptions.ArchiveOptions.FileName=NewFileName("Sample Files")viewer.View(viewOptions)EndUsingEndSubEndModule
The image below demonstrates the result.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.