Document Viewer API

We are happy to announce the release of version 19.3 of GroupDocs.Viewer for .NET. In this release, we have added several new features that target the PDF documents, archives and the source code files of Visual Basic and C#. Along with 2 bug fixes, we have made a couple of improvements for rendering of ZIP archives and vCard documents. For detailed information about the latest release, please have a look at the release notes.

What’s New in this Release?

Setting Passwords and Permissions for PDF Documents

PDF format allows setting the Owner password and the User password to restrict access to the document. The Owner password is used to change the permissions of the document whereas the User password is required when opening a PDF document. Along with the passwords, PDF format supports setting permissions such as allow or deny printing, modification and data extraction. In this release, we have added the support of setting the Owner password, User password, and the file permissions while rendering the document into PDF.

The following is a simple way to create and use the PDF file’s security options using GroupDocs.Viewer for .NET:

// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET
// Setup GroupDocs.Viewer config
ViewerConfig viewerConfig = new ViewerConfig();
viewerConfig.StoragePath = @"C:\storage";
// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(viewerConfig);
// Create PDF file security
string ownerPassword = "owner password";
string userPassword = "user password";
PdfFilePermissions denyPrinting = PdfFilePermissions.All ^ PdfFilePermissions.Printing;
PdfFileSecurity pdfFileSecurity = new PdfFileSecurity(ownerPassword, userPassword, denyPrinting);
// Create options
PdfFileOptions pdfFileOptions = new PdfFileOptions();
pdfFileOptions.PdfFileSecurity = pdfFileSecurity;
string guid = "document.doc";
FileContainer fileContainer = imageHandler.GetPdfFile(guid, pdfFileOptions);

Working with Folders within the Archives

In the previous version, we introduced the support of rendering archive documents. The rendering of archive documents shows a list of the items (files and folders) located in the root of the archive. In the latest release, we have made it possible to get the list of the folders within the archive and render the content from those folders. The following sections demonstrate how to work with the folders located in an archive document.

Getting List of Folders within an Archive

The following code snippet shows how to get the list of folders within an archive:

// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET
// Setup GroupDocs.Viewer config
ViewerConfig config = new ViewerConfig();
config.StoragePath = @"C:\storage";
// Create HTML or image handler
ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
string guid = "archive.zip";
// Get archive document info
ArchiveDocumentInfoContainer documentInfoContainer = htmlHandler.GetDocumentInfo(guid) as ArchiveDocumentInfoContainer;
foreach (string folderName in documentInfoContainer.Folders)
Console.WriteLine("Folder name: {0}", folderName);

Getting List of Folders in a Specific Folder

There might be the case when you have sub-folders within a folder located in the root of the archive. In that case, to get the list of sub-folders you can simply specify the folder name in ArchiveOptions.FolderName property of HtmlOptions/ImageOptions class.

// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET
// Setup GroupDocs.Viewer config
ViewerConfig config = new ViewerConfig();
config.StoragePath = @"C:\storage";
// Create HTML or image handler
ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
string guid = "archive.zip";
// set option to retrieve list of folders from certain folder.
HtmlOptions options = new HtmlOptions();
options.ArchiveOptions.FolderName = "FirstLevelFolder/SecondLevelFolder";
// Get archive document info
ArchiveDocumentInfoContainer documentInfoContainer = htmlHandler.GetDocumentInfo(guid, options) as ArchiveDocumentInfoContainer;
foreach (string folderName in documentInfoContainer.Folders)
Console.WriteLine("Folder name: {0}", folderName);

Rendering Specified Folder within Archive

To render the content of a folder, simply specify the folder name in
ArchiveOptions.FolderName property and call GetPages function as shown in the following code snippet.

// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET
// Setup GroupDocs.Viewer config
ViewerConfig config = new ViewerConfig();
config.StoragePath = @"C:\storage";
// Create image handler or use ViewerHtmlHandler to render into HTML
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
string guid = "sample.zip";
// Create image options with specified folder name (use HtmlOptions to render into HTML)
ImageOptions options = new ImageOptions();
options.ArchiveOptions.FolderName = "FirstLevelFolder/SecondLevelFolder";
// Render document into image
List<PageImage> pages = imageHandler.GetPages(guid, options);
foreach (PageImage page in pages)
{
// use page.Stream to work with rendering result
}

Support of Visual Basic (.vb) and C# (.cs) Files

Using the latest release, you will be able to view the source code files of Visual Basic and C#. The rendering of these source code files is available in both, the HTML-based and image-based rendering.

Haven’t Used GroupDocs.Viewer Before?

In case you haven’t yet tried our API but are interested in using it, the following resources will be helpful for you to get started.

Stay Tuned for Updates!

If you don’t want to miss out any news or announcements on GroupDocs products, stay tuned to our blog and keep visiting frequently.