Render images as HTML, PDF, PNG, and JPEG files
Leave feedback
On this page
GroupDocs.Viewer for .NET allows you to load images in various formats and convert them to HTML, PDF, PNG, and JPEG. Incorporate this library into your .NET application (web or desktop) to build your own image viewer.
To start with the GroupDocs.Viewer API, create a Viewer class instance. Pass an image you want to view to the class constructor. You can load the image from a file or stream. Call one of the Viewer.View method overloads to convert the image to HTML, PDF, PNG, or JPEG format. For multipage images (such as TIFF, CDR, DICOM, WebP, and so on), you can specify the pages to render.
GroupDocs.Viewer can detect the image format automatically based on information in the file header.
Note
All Photoshop-related image formats (AI, PSD, and PSB) currently are not supported by the GroupDocs.Viewer.CrossPlatform.
Render images as HTML
Create an HtmlViewOptions class instance and pass it to the Viewer.View method to convert an image to HTML. The HtmlViewOptions class properties allow you to control the conversion process. For instance, you can embed all external resources in the generated HTML file, minify the output file, and optimize it for printing. Refer to the following documentation section for details: Rendering to HTML.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("vector-image.svg")){// Create an HTML file.varviewOptions=HtmlViewOptions.ForEmbeddedResources("output.html");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("vector-image.svg")' Create an HTML file.
DimviewOptions=HtmlViewOptions.ForEmbeddedResources("output.html")viewer.View(viewOptions)EndUsingEndSubEndModule
The path format for the folder with external resources
The resource URL format
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("vector-image.svg")){// Specify the HTML file name and location of external resources.// {0} is replaced with the resource name in the output file name.varviewOptions=HtmlViewOptions.ForExternalResources("output.html","output/resource_{0}","output/resource_{0}");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("vector-image.svg")' Specify the HTML file name and location of external resources.
' {0} is replaced with the resource name in the output file name.
DimviewOptions=HtmlViewOptions.ForExternalResources("output.html","output/resource_{0}","output/resource_{0}")viewer.View(viewOptions)EndUsingEndSubEndModule
The result is shown below. The image is placed in a separate folder.
Render images as PDF
Create a PdfViewOptions class instance and pass it to the Viewer.View method to convert an image to PDF. The PdfViewOptions class properties allow you to control the conversion process. For instance, you can protect the output PDF file, reorder its pages, and specify the quality of document images. Refer to the following documentation section for details: Rendering to PDF.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("vector-image.svg")){// Create a PDF file.varviewOptions=newPdfViewOptions("output.pdf");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("vector-image.svg")' Create a PDF file.
DimviewOptions=NewPdfViewOptions("output.pdf")viewer.View(viewOptions)EndUsingEndSubEndModule
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("vector-image.svg")){// Create a PNG image.varviewOptions=newPngViewOptions("output.png");// Set width and height.viewOptions.Width=1600;viewOptions.Height=900;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("vector-image.svg")' Create a PNG image.
DimviewOptions=NewPngViewOptions("output.png")' Set width and height.
viewOptions.Width=1600viewOptions.Height=900viewer.View(viewOptions)EndUsingEndSubEndModule
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...using(varviewer=newViewer("vector-image.svg")){// Create a JPEG image.varviewOptions=newJpgViewOptions("output.jpg");// Set width and height.viewOptions.Width=1600;viewOptions.Height=900;viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())Usingviewer=NewViewer("vector-image.svg")' Create a JPEG image.
DimviewOptions=NewJpgViewOptions("output.jpg")' Set width and height.
viewOptions.Width=1600viewOptions.Height=900viewer.View(viewOptions)EndUsingEndSubEndModule
Render a PSD file with custom fonts
When you render a PSD file with custom fonts, you can specify a folder that contains necessary fonts to prevent font substitution during rendering. To do this, follow the steps below:
Create a FolderFontSource class instance and specify a path to the folder that stores custom fonts. Pass a SearchOption enumeration member to the class constructor to define the search scope. The following options are available:
TopFolderOnly—Searches for the fonts only in the current folder.
AllFolders—Searches for the fonts in the current folder and its subfolders.
Call the FontSettings.SetFontSources static method and pass the specified font source to this method as a parameter. This method allows you to specify multiple font sources.
You can also set the ViewOptions.DefaultFontName property to specify the default font that should be used when a particular font is not found.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Fonts;usingGroupDocs.Viewer.Options;// ...// Specify a folder that stores custom fonts used in a PSD file.varfontSource=newFolderFontSource(@"C:\custom_fonts_folder",SearchOption.AllFolders);FontSettings.SetFontSources(fontSource);using(varviewer=newViewer("sample.psd")){// Convert a PSD file to PNG.varviewOptions=newPngViewOptions("output.png");// Specify the default font that should be used to replace missing fonts.viewOptions.DefaultFontName="Arial";viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.FontsImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())' Specify a folder that stores custom fonts used in a PSD file.
DimfontSource=NewFolderFontSource("C:\custom_fonts_folder",SearchOption.AllFolders)FontSettings.SetFontSources(fontSource)Usingviewer=NewViewer("sample.psd")' Convert a PSD file to PNG.
DimviewOptions=NewPngViewOptions("output.png")' Specify the default font that should be used to replace missing fonts.
viewOptions.DefaultFontName="Arial"viewer.View(viewOptions)EndUsingEndSubEndModule
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.