# Render images as HTML, PDF, PNG, and JPEG files This topic describes how to use the GroupDocs.Viewer .NET API (C#) to convert images to HTML, PDF, PNG, and JPEG formats. [GroupDocs.Viewer for .NET](https://products.groupdocs.com/viewer/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](https://reference.groupdocs.com/viewer/net/groupdocs.viewer/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](https://reference.groupdocs.com/viewer/net/groupdocs.viewer/viewer/methods/view/index) 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. {{< button style="primary" link="https://products.groupdocs.app/viewer/image" >}} {{< icon "gdoc_person" >}} View image files online {{< /button >}} {{< button style="primary" link="https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET" >}} {{< icon "gdoc_github" >}} View demos and examples on GitHub {{< /button >}} ## Supported image file formats GroupDocs.Viewer supports the following image file formats: * [.AI (Adobe Illustrator Artwork)](https://docs.fileformat.com/image/ai/) * [.APNG (Animated Portable Network Graphic)](https://docs.fileformat.com/image/apng/) * [.BMP (Bitmap Image)](https://docs.fileformat.com/image/bmp) * [.CDR (CorelDRAW Image File)](https://docs.fileformat.com/image/cdr) * [.CGM (Computer Graphics Metafile)](https://docs.fileformat.com/page-description-language/cgm) * [.CMX (Corel Presentation Exchange Image)](https://docs.fileformat.com/image/cmx) * [.DCM (DICOM Image)](https://docs.fileformat.com/image/dicom) * [.DIB (Device Independent Bitmap File)](https://docs.fileformat.com/image/dib) * [.DJVU (DjVu Image)](https://docs.fileformat.com/image/djvu) * [.DNG (Digital Negative Image)](https://docs.fileformat.com/image/dng) * [.EMF (Enhanced Windows Metafile)](https://docs.fileformat.com/image/emf) * [.EMZ (Windows Compressed Enhanced Metafile)](https://docs.fileformat.com/image/emz/) * [.EPS (Encapsulated PostScript File)](https://docs.fileformat.com/page-description-language/eps) * [.FODG (OpenDocument Flat XML Graphics)](https://docs.fileformat.com/image/fodg/) * [.GIF (Graphical Interchange Format)](https://docs.fileformat.com/image/gif) * [.ICO (Icon File)](https://docs.fileformat.com/image/ico) * [.J2C (JPEG 2000 Code Stream)](https://docs.fileformat.com/image/j2c/) * [.J2K (JPEG 2000 Image)](https://docs.fileformat.com/image/j2k/) * [.JP2 (JPEG 2000 Core Image File)](https://docs.fileformat.com/image/jp2/) * [.JPC (JPEG 2000 Code Stream File)](https://docs.fileformat.com/image/jpc/) * [.JPEG / .JPG (JPEG Image)](https://docs.fileformat.com/image/jpeg) * [.JPF (JPEG 2000 Image)](https://docs.fileformat.com/image/jpf/) * [.JPM (JPEG 2000 Multi-layer Image Format)](https://docs.fileformat.com/image/jpm/) * [.JPX (JPEG 2000 Image File)](https://docs.fileformat.com/image/jpx/) * [.JLS (JPEG-LS Image)](https://docs.fileformat.com/) * [.ODG (OpenDocument Graphics File)](https://docs.fileformat.com/image/odg) * [.OTG (OpenDocument Graphic Template)](https://docs.fileformat.com/image/otg/) * [.PCL (Printer Command Language Document)](https://docs.fileformat.com/page-description-language/pcl) * [.PNG (Portable Network Graphics)](https://docs.fileformat.com/image/png) * [.PS (PostScript File)](https://docs.fileformat.com/page-description-language/ps) * [.PSB (Photoshop Large Document Format)](https://docs.fileformat.com/image/psb) * [.PSD (Adobe Photoshop Document)](https://docs.fileformat.com/image/psd) * [.SVG (Scalable Vector Graphics File)](https://docs.fileformat.com/page-description-language/svg) * [.SVGZ (Compressed SVG File)](https://docs.fileformat.com/image/svgz/) * [.TGA (TARGA Graphics)](https://docs.fileformat.com/image/tga/) * [.TIF / .TIFF (Tagged Image File Format)](https://docs.fileformat.com/image/tiff) * [.WEBP (WebP Image)](https://docs.fileformat.com/image/webp) * [.WMF (Windows Metafile)](https://docs.fileformat.com/image/wmf) * [.WMZ (Compressed Windows Metafile)](https://docs.fileformat.com/image/wmz/) GroupDocs.Viewer can detect the image format automatically based on information in the file header. {{< alert style="info" >}}Adobe-related image formats (AI, PSD, and PSB) are not supported by the cross-platform runtime packages ([GroupDocs.Viewer.Net60](https://www.nuget.org/packages/GroupDocs.Viewer.Net60), [GroupDocs.Viewer.Net80](https://www.nuget.org/packages/GroupDocs.Viewer.Net80), and [GroupDocs.Viewer.Net100](https://www.nuget.org/packages/GroupDocs.Viewer.Net100)). They are supported on Windows: target .NET Framework or a `-windows` target framework, such as `net10.0-windows`. See [System requirements]({{< ref "viewer/net/getting-started/system-requirements.md" >}}).{{< /alert >}} ## Render images as HTML Create an [HtmlViewOptions](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/htmlviewoptions) class instance and pass it to the [Viewer.View](https://reference.groupdocs.com/viewer/net/groupdocs.viewer/viewer/methods/view/index) 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]({{< ref "viewer/net/developer-guide/rendering-documents/rendering-to-html/_index.md" >}}). ### Create an HTML file with embedded resources To embed an image in an HTML page, call the [HtmlViewOptions.ForEmbeddedResources](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/htmlviewoptions/methods/forembeddedresources/index) method and specify the output file name. {{< tabs "render-image-to-html">}} {{< tab "C#" >}} ```csharp using GroupDocs.Viewer; using GroupDocs.Viewer.Options; // ... using (var viewer = new Viewer("vector-image.svg")) { // Create an HTML file. var viewOptions = HtmlViewOptions.ForEmbeddedResources("output.html"); viewer.View(viewOptions); } ``` {{< /tab >}} {{< tab "VB.NET">}} ```vb Imports GroupDocs.Viewer Imports GroupDocs.Viewer.Options ' ... Module Program Sub Main(args As String()) Using viewer = New Viewer("vector-image.svg") ' Create an HTML file. Dim viewOptions = HtmlViewOptions.ForEmbeddedResources("output.html") viewer.View(viewOptions) End Using End Sub End Module ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "output.html" >}} ```text HTML file (1.3 MB) ``` [Download full output](https://docs.groupdocs.com/viewer/net/_output_files/rendering-basics/render-images/RenderImageToHtml/output.html) {{< /tab >}} {{< /tabs >}} ### Create an HTML file with external resources To save an image to a separate folder, call the [HtmlViewOptions.ForExternalResources](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/htmlviewoptions/methods/forexternalresources/index) method and pass the following parameters: * The output file path format * The path format for the folder with external resources * The resource URL format {{< tabs "render-image-to-html-external">}} {{< tab "C#" >}} ```csharp using GroupDocs.Viewer; using GroupDocs.Viewer.Options; // ... using (var viewer = new Viewer("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. var viewOptions = HtmlViewOptions.ForExternalResources("output.html", "output/resource_{0}", "output/resource_{0}"); viewer.View(viewOptions); } ``` {{< /tab >}} {{< tab "VB.NET">}} ```vb Imports GroupDocs.Viewer Imports GroupDocs.Viewer.Options ' ... Module Program Sub Main(args As String()) Using viewer = New Viewer("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. Dim viewOptions = HtmlViewOptions.ForExternalResources("output.html", "output/resource_{0}", "output/resource_{0}") viewer.View(viewOptions) End Using End Sub End Module ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-image-to-html-external.zip" >}} ```text output.html (269 bytes) output/resource_1 (5 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/net/_output_files/rendering-basics/render-images/RenderImageToHtmlExternal/render-image-to-html-external.zip) {{< /tab >}} {{< /tabs >}} The image is placed in a separate folder. ## Render images as PDF Create a [PdfViewOptions](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/pdfviewoptions) class instance and pass it to the [Viewer.View](https://reference.groupdocs.com/viewer/net/groupdocs.viewer/viewer/methods/view/index) 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]({{< ref "viewer/net/developer-guide/rendering-documents/rendering-to-pdf/_index.md" >}}). {{< tabs "render-image-to-pdf">}} {{< tab "C#" >}} ```csharp using GroupDocs.Viewer; using GroupDocs.Viewer.Options; // ... using (var viewer = new Viewer("vector-image.svg")) { // Create a PDF file. var viewOptions = new PdfViewOptions("output.pdf"); viewer.View(viewOptions); } ``` {{< /tab >}} {{< tab "VB.NET">}} ```vb Imports GroupDocs.Viewer Imports GroupDocs.Viewer.Options ' ... Module Program Sub Main(args As String()) Using viewer = New Viewer("vector-image.svg") ' Create a PDF file. Dim viewOptions = New PdfViewOptions("output.pdf") viewer.View(viewOptions) End Using End Sub End Module ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "output.pdf" >}} ```text Binary file (PDF, 38 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/net/_output_files/rendering-basics/render-images/RenderImageToPdf/output.pdf) {{< /tab >}} {{< /tabs >}} ## Convert images to PNG Create a [PngViewOptions](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/pngviewoptions) class instance and pass it to the [Viewer.View](https://reference.groupdocs.com/viewer/net/groupdocs.viewer/viewer/methods/view/index) method to convert an image to PNG. Use the [PngViewOptions.Height](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/pngviewoptions/properties/height) and [PngViewOptions.Width](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/pngviewoptions/properties/width) properties to specify the output image size in pixels. {{< tabs "render-image-to-png">}} {{< tab "C#" >}} ```csharp using GroupDocs.Viewer; using GroupDocs.Viewer.Options; // ... using (var viewer = new Viewer("vector-image.svg")) { // Create a PNG image. var viewOptions = new PngViewOptions("output.png"); // Set width and height. viewOptions.Width = 1600; viewOptions.Height = 900; viewer.View(viewOptions); } ``` {{< /tab >}} {{< tab "VB.NET">}} ```vb Imports GroupDocs.Viewer Imports GroupDocs.Viewer.Options ' ... Module Program Sub Main(args As String()) Using viewer = New Viewer("vector-image.svg") ' Create a PNG image. Dim viewOptions = New PngViewOptions("output.png") ' Set width and height. viewOptions.Width = 1600 viewOptions.Height = 900 viewer.View(viewOptions) End Using End Sub End Module ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "output.png" >}} ```text Binary file (PNG, 247 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/net/_output_files/rendering-basics/render-images/RenderImageToPng/output.png) {{< /tab >}} {{< /tabs >}} ## Convert images to JPEG Create a [JpgViewOptions](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/jpgviewoptions) class instance and pass it to the [Viewer.View](https://reference.groupdocs.com/viewer/net/groupdocs.viewer/viewer/methods/view/index) method to convert an image to JPEG. Use the [JpgViewOptions.Height](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/jpgviewoptions/properties/height) and [JpgViewOptions.Width](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/jpgviewoptions/properties/width) properties to specify the output image size in pixels. {{< tabs "render-image-to-jpg">}} {{< tab "C#" >}} ```csharp using GroupDocs.Viewer; using GroupDocs.Viewer.Options; // ... using (var viewer = new Viewer("vector-image.svg")) { // Create a JPEG image. var viewOptions = new JpgViewOptions("output.jpg"); // Set width and height. viewOptions.Width = 1600; viewOptions.Height = 900; viewer.View(viewOptions); } ``` {{< /tab >}} {{< tab "VB.NET">}} ```vb Imports GroupDocs.Viewer Imports GroupDocs.Viewer.Options ' ... Module Program Sub Main(args As String()) Using viewer = New Viewer("vector-image.svg") ' Create a JPEG image. Dim viewOptions = New JpgViewOptions("output.jpg") ' Set width and height. viewOptions.Width = 1600 viewOptions.Height = 900 viewer.View(viewOptions) End Using End Sub End Module ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "output.jpg" >}} ```text Binary file (JPG, 141 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/net/_output_files/rendering-basics/render-images/RenderImageToJpg/output.jpg) {{< /tab >}} {{< /tabs >}} ## 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: 1. Create a [FolderFontSource](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.fonts/folderfontsource) class instance and specify a path to the folder that stores custom fonts. Pass a [SearchOption](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.fonts/folderfontsource/properties/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. 2. Call the [FontSettings.SetFontSources](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.fonts/fontsettings/methods/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](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/baseviewoptions/properties/defaultfontname) property to specify the default font that should be used when a particular font is not found. {{< tabs "render-psd-with-custom-fonts">}} {{< tab "C#" >}} ```csharp using GroupDocs.Viewer; using GroupDocs.Viewer.Fonts; using GroupDocs.Viewer.Options; // ... // Specify a folder that stores custom fonts used in a PSD file. System.IO.Directory.CreateDirectory("custom_fonts_folder"); // SearchOption is named in full: System.IO, which .NET 6+ projects import by default, has one too. var fontSource = new FolderFontSource("custom_fonts_folder", GroupDocs.Viewer.Fonts.SearchOption.AllFolders); FontSettings.SetFontSources(fontSource); using (var viewer = new Viewer("sample.psd")) { // Convert a PSD file to PNG. var viewOptions = new PngViewOptions("output.png"); // Specify the default font that should be used to replace missing fonts. viewOptions.DefaultFontName = "Arial"; viewer.View(viewOptions); } ``` {{< /tab >}} {{< tab "VB.NET">}} ```vb Imports GroupDocs.Viewer Imports GroupDocs.Viewer.Fonts Imports GroupDocs.Viewer.Options ' ... Module Program Sub Main(args As String()) ' Specify a folder that stores custom fonts used in a PSD file. System.IO.Directory.CreateDirectory("custom_fonts_folder") Dim fontSource = New FolderFontSource("custom_fonts_folder", SearchOption.AllFolders) FontSettings.SetFontSources(fontSource) Using viewer = New Viewer("sample.psd") ' Convert a PSD file to PNG. Dim viewOptions = New PngViewOptions("output.png") ' Specify the default font that should be used to replace missing fonts. viewOptions.DefaultFontName = "Arial" viewer.View(viewOptions) End Using End Sub End Module ``` {{< /tab >}} {{< tab "sample.psd" >}} {{< tab-text >}} `sample.psd` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/net/_sample_files/rendering-basics/render-images/sample.psd) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "output.png" >}} ```text Binary file (PNG, 623 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/net/_output_files/rendering-basics/render-images/RenderPsdWithCustomFonts/output.png) {{< /tab >}} {{< /tabs >}} ## Image files rendering demo The [View CDR and other images](https://products.groupdocs.app/viewer/cdr) app is available to test and preview rendering output for images and other document formats.