View and render documents with GroupDocs.Viewer
Leave feedback
On this page
GroupDocs.Viewer renders a document into something a browser can display — HTML, PDF, or one image per page — without Microsoft Office or any other external software. It is the API to reach for when you want to show a document rather than change it.
Every example below opens contract.docx and is ready to copy into a console app once you have installed the package.
Render a document to HTML
Rendering to HTML gives you one .html file per page. ForEmbeddedResources inlines images, fonts and stylesheets into each page, so a page is self-contained and needs no companion files.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;using(Viewerviewer=newViewer("contract.docx")){// {0} is replaced with the page number, so page 1 becomes page_1.htmlHtmlViewOptionsviewOptions=HtmlViewOptions.ForEmbeddedResources("viewer-render-to-html/page_{0}.html");viewer.View(viewOptions);}
contract.docx is the sample file used in this example. Click here to download it.
To keep resources as separate files next to the HTML instead of inlining them, use HtmlViewOptions.ForExternalResources — useful when several pages share the same images and you want them cached once.
Render a document to PDF
Rendering to PDF produces a single file, which is the usual choice for printing or archiving.
Rendering to images gives you one PNG per page — the right output for thumbnails and previews. PngViewOptions also accepts a width and height if you need a fixed size.
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;using(Viewerviewer=newViewer("contract.docx")){PngViewOptionsviewOptions=newPngViewOptions("viewer-render-to-png/page_{0}.png");// Render only the first two pagesviewer.View(viewOptions,1,2);}
contract.docx is the sample file used in this example. Click here to download it.
Before rendering you often want to know what you are dealing with — how many pages, what format, whether it is encrypted. GetViewInfo answers that without rendering anything.
The examples above cover the common cases. GroupDocs.Viewer also renders archives, CAD drawings, email messages, Outlook data files and Visio diagrams, caches rendered output, and processes attachments.