This quick start guide shows you how to get started with GroupDocs.Viewer for .NET. You will create a .NET console application, install the GroupDocs.Viewer NuGet package, and render a DOCX document to HTML, PDF, and PNG using C#.
GroupDocs.Viewer is a .NET document rendering library that supports 190+ file formats and renders supported documents to HTML, PDF, PNG, or JPG without requiring Microsoft Office or other third-party applications.
Optionally, you have a Temporary License to evaluate all GroupDocs.Viewer features without evaluation limitations.
Create a .NET Application and Install GroupDocs.Viewer
Create a new .NET console application and add the GroupDocs.Viewer NuGet package.
Starting with version 26.8, GroupDocs.Viewer uses TFM-split packaging. Install a single package, and NuGet automatically restores the runtime package that matches your project’s target framework. See Installation for details.
Create a console app
dotnet new console -n DemoApp -o demo-app
cd demo-app
Install the GroupDocs.Viewer package
Install GroupDocs.Viewer:
dotnet add package GroupDocs.Viewer
After the installation completes, your project file contains a package reference similar to the following:
The following example renders a Microsoft Word document to HTML with embedded resources.
You can download the complete example project here.
usingSystem.IO;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// Get the absolute path to the license filestringlicensePath=Path.GetFullPath("./GroupDocs.Viewer.lic");if(File.Exists(licensePath)){// Apply the licenseLicenselicense=newLicense();license.SetLicense(licensePath);}// Load the DOCX documentusing(Viewerviewer=newViewer("./sample.docx")){// Configure HTML view optionsHtmlViewOptionshtmlOptions=HtmlViewOptions.ForEmbeddedResources("render_docx_to_html/page_{0}.html");// Render the DOCX document to HTMLviewer.View(htmlOptions);}
sample.docx is the source document used in this example. Click here to download it.
new Viewer("./sample.docx"): loads the DOCX document.
HtmlViewOptions.ForEmbeddedResources("render_docx_to_html/page_{0}.html"): configures HTML output with embedded resources.
viewer.View(htmlOptions): renders the document and saves the output HTML files page_1.html, page_2.html, etc.
Example 2: Render a DOCX Document to PDF
The following example renders the same DOCX document to a single PDF file.
You can download the complete example project here.
usingSystem.IO;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// Get the absolute path to the license filestringlicensePath=Path.GetFullPath("./GroupDocs.Viewer.lic");if(File.Exists(licensePath)){// Apply the licenseLicenselicense=newLicense();license.SetLicense(licensePath);}// Load the DOCX documentusing(Viewerviewer=newViewer("./sample.docx")){// Configure PDF view optionsPdfViewOptionspdfOptions=newPdfViewOptions("render_docx_to_pdf/output.pdf");// Render the DOCX document to PDFviewer.View(pdfOptions);}
sample.docx is the source document used in this example. Click here to download it.
new Viewer("./sample.docx"): loads the DOCX document.
new PdfViewOptions("render_docx_to_pdf/output.pdf"): configures PDF output.
viewer.View(pdfOptions): renders the document and saves the result as a PDF file.
Example 3: Render a DOCX Document to PNG
The following example renders each page of a DOCX document as a separate PNG image.
You can download the complete example project here.
usingSystem.IO;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// Get the absolute path to the license filestringlicensePath=Path.GetFullPath("./GroupDocs.Viewer.lic");if(File.Exists(licensePath)){// Apply the licenseLicenselicense=newLicense();license.SetLicense(licensePath);}// Load the DOCX documentusing(Viewerviewer=newViewer("./sample.docx")){// Configure PNG view optionsPngViewOptionspngOptions=newPngViewOptions("render_docx_to_png/output_{0}.png");// Render the DOCX document to PNGviewer.View(pngOptions);}
sample.docx is the source document used in this example. Click here to download it.