DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironpdf.com

C# PDF Viewers

Viewing PDFs in applications is a common request that is easily solved with the PDF Library for .NET.


Step 1

1. Installing IronPDF into Your Project

Use NuGet package manager to install IronPDF:
https://www.nuget.org/packages/IronPdf

PM > Install-Package IronPdf

IronPDF DLL can also be downloaded and manually installed.


How to Tutorial

2. PDF Viewers for .NET

We are working on a visual framework for viewing PDFs in C#/.Net - in the mean time you have lots of viable free options without resorting to Adobe Acrobat.

2.1. ASP.Net & MVC PDF viewer.

For web applications - PDFs can be viewed in a browser window or iframe. You may also use the amazing pdf.js library from mozilla to leverage a full PDF viewer written in pure javascript code.

https://mozilla.github.io/pdf.js/

2.2. WPF C# PDF Viewer

For viewing PDF documents directly in WPF you can use the native WebBrowser control.

2.3. Windows Forms PDF Viewer

For viewing PDF documents directly in windows forms (WinForms) applications the WebBrowser control is also a good choice.

2.4. Viewing a PDF in a the Default System PDF Viewer

To open a PDF from any application in an external window, we may use a trick involving System.Diagnostics.Process.Start.

This will generally open the PDF in the default web browser which supports viewing PDF content, or Adobe Acrobat if installed.

C#:

// Render any HTML fragment or document to HTML
var Renderer = new IronPdf.ChromePdfRenderer();
var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
var OutputPath = "ChromePdfRenderer.pdf";
PDF.SaveAs(OutputPath);
// This neat trick opens our PDF file so we can see the result in our default PDF viewer
System.Diagnostics.Process.Start(OutputPath);
Enter fullscreen mode Exit fullscreen mode

VB:

' Render any HTML fragment or document to HTML
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>")
Dim OutputPath = "ChromePdfRenderer.pdf"
PDF.SaveAs(OutputPath)
' This neat trick opens our PDF file so we can see the result in our default PDF viewer
System.Diagnostics.Process.Start(OutputPath)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)