Click or drag to resize

Getting Started with ExpertPdf PDF Viewer for ASP.NET and ASP.NET Core

ExpertPdf PDF Viewer for ASP.NET displays PDF documents in your web pages with a built-in viewer that works in every modern browser, on desktops, tablets and phones. The users get page thumbnails, the document outline (bookmarks) and attachments panels, text search and selection, zoom and fit modes, page layouts, printing and download. No browser plug-in and no Adobe Reader are needed.

One assembly, PdfViewerAspNet.dll, serves both ASP.NET platforms:

  • ASP.NET Web Forms (.NET Framework 4.6.2 or later): the PdfViewer server control.

  • ASP.NET Core (.NET 8 or later): the <expertpdf-viewer> tag helper for Razor Pages and MVC views, and the UseExpertPdfViewer middleware.

Features
  • Display a document from an address - a file of your application or of another web site - or from memory, for example a document you have just created with ExpertPdf HTML to PDF Converter.

  • Set how the document opens: the page, the zoom or fit mode, the page layout and the navigation panel.

  • Show or hide the toolbar, the scrollbars and single toolbar buttons (open, navigation panel, find, page navigation, zoom, print, download, presentation mode, document properties); a light or dark theme, or as set in the browser.

  • Protect the document before it is sent to the browser: a password to open it, and the permissions to print and to copy its content.

  • Drive the viewer from the page with the JavaScript client API: navigation, zoom, layout, panels, find, theme, toolbar buttons, printing, the password of a protected document, and events.

What's new
  • Find text from the page: find, findNext, findPrevious and the searchcompleted event of the client API.

  • The passwordrequired event of the client API: the page gives the password of a protected document (or stops opening it); a wrong password is reported. Without a handler the viewer asks the user, as before.

  • A light or dark theme (ViewerTheme, theme) and properties that show or hide single toolbar buttons (ShowFindButton, show-find-button, ...).

Installation

Install the ExpertPdf.PdfViewer.AspNet NuGet package (https://www.nuget.org/packages/ExpertPdf.PdfViewer.AspNet/):

dotnet add package ExpertPdf.PdfViewer.AspNet

Or use the downloaded assemblies: copy Bin\PdfViewerAspNet.dll to the Bin folder of your Web Forms application, or reference Bin\.NET_8.0\PdfViewerAspNet.dll from your ASP.NET Core project (with the System.Drawing.Common package). The download also contains Web Forms samples (C#, VB.NET) and an ASP.NET Core sample.

Getting started with ASP.NET Web Forms

Register the control in the page and add it:

XML
<%@ Register Assembly="PdfViewerAspNet" Namespace="PdfViewer4AspNet" TagPrefix="epdf" %>

<epdf:PdfViewer ID="pdfViewer" runat="server" PdfSourceURL="~/files/report.pdf"
    PageFitMode="FitH" Width="100%" Height="700px" />

The control serves the viewer files itself: there is nothing to add to web.config. See The Web Forms control.

Getting started with ASP.NET Core

In Program.cs, add the viewer before the routing:

C#
using PdfViewer4AspNet;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();

app.UseExpertPdfViewer(options => options.LicenseKey = "your license key");
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.Run();

Register the tag helper in Pages/_ViewImports.cshtml (or Views/_ViewImports.cshtml):

@addTagHelper *, PdfViewerAspNet

And add the viewer to a page or a view:

XML
<expertpdf-viewer src="~/files/report.pdf" fit="FitH" height="700px"></expertpdf-viewer>

See The ASP.NET Core tag helper.

Licensing

A license key is emailed to you when you purchase the product. Set it with the LicenseKey property of the Web Forms control, or once for the application with the LicenseKey option of UseExpertPdfViewer in ASP.NET Core. Without a valid license key the viewer works the same and shows an evaluation notice.

Next steps
See Also