Getting Started with Smart PDF Viewer
2 Sep 20257 minutes to read
This section briefly explains how to include Blazor Smart PDF Viewer component in your Blazor Web App using Visual Studio and Visual Studio code.
Prerequisites
NOTE
Syncfusion® Blazor Smart PDF Viewer Component is compatible with both
OpenAI
andAzure OpenAI
, and fully support Server Interactivity mode apps.
Create a new Blazor Web App in Visual Studio
You can create a Blazor Web App using Visual Studio 2022 via Microsoft Templates or the Syncfusion® Blazor Extension.
Install Syncfusion® Blazor Smart PDF Viewer and Themes NuGet in the App
To add Blazor Smart PDF Viewer component in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search and install Syncfusion.Blazor.SfSmartPdfViewer
and Syncfusion.Blazor.Themes.
Alternatively, you can utilize the following package manager command to achieve the same.
Install-Package Syncfusion.Blazor.SfSmartPdfViewer -Version 31.2.*
Install-Package Syncfusion.Blazor.Themes -Version 31.2.*
NOTE
Syncfusion® Blazor components are available in nuget.org. Refer to NuGet packages topic for available NuGet packages list with component details.
Prerequisites
NOTE
Syncfusion® Blazor Smart PDF Viewer Component is compatible with both
OpenAI
andAzure OpenAI
, and fully support Server Interactivity mode apps.
Create a new Blazor Web App in Visual Studio Code
You can create a Blazor Web App using Visual Studio 2022 via Microsoft Templates or the Syncfusion® Blazor Extension.
You need to configure the corresponding Interactive render mode and Interactivity location while creating a Blazor Web Application.
For example, in a Blazor Web App with the Server
interactive render mode, use the following commands.
dotnet new blazor -o BlazorWebApp -int Server
cd BlazorWebApp
cd BlazorWebApp.Client
NOTE
For more information on creating a Blazor Web App with various interactive modes and locations, refer to this link.
Install Syncfusion® Blazor Smart PDF Viewer and Themes NuGet in the App
If you utilize Server
render modes in the Blazor Web App need to be install Syncfusion® Blazor components NuGet packages within the server project.
- Press Ctrl+` to open the integrated terminal in Visual Studio Code.
- Ensure you’re in the project root directory where your
.csproj
file is located. - Run the following command to install a
Syncfusion.Blazor.SfSmartPdfViewer
and Syncfusion.Blazor.Themes NuGet package and ensure all dependencies are installed.
dotnet add package Syncfusion.Blazor.SfSmartPdfViewer -v 31.2.*
dotnet add package Syncfusion.Blazor.Themes -v 31.2.*
dotnet restore
NOTE
Syncfusion® Blazor components are available in nuget.org. Refer to NuGet packages topic for available NuGet packages list with component details.
Register Syncfusion® Blazor Service
Interactive Render Mode | Description |
---|---|
Server | Open ~/_Imports.razor file, which is located in the Components folder. |
Import the Syncfusion.Blazor and Syncfusion.Blazor.SmartPdfViewer namespace.
@using Syncfusion.Blazor
@using Syncfusion.Blazor.SmartPdfViewer
If the Interactive Render Mode is set to Server
, your project will contain a single ~/Program.cs file. So, you should register the Syncfusion® Blazor Service only in that ~/Program.cs file.
using Syncfusion.Blazor;
var builder = WebApplication.CreateBuilder(args);
// Add service to the container.
builder.Services.AddSyncfusionBlazor();
var app = builder.Build();
....
To Configure Azure OpenAI Service
In Visual Studio, Go to Tools → NuGet Package Manager → Package Manager Console. Run these commands one by one:
Install-Package Azure.AI.OpenAI
Install-Package Microsoft.Extensions.AI
Install-Package Microsoft.Extensions.AI.OpenAI -Version 9.8.0-preview.1.25412.6
In Visual Studio Code, Open terminal in VS Code. Run these commands:
dotnet add package Azure.AI.OpenAI
dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.Extensions.AI.OpenAI --version 9.8.0-preview.1.25412.6
To configure the AI service, add the following settings to the ~/Program.cs file in your Blazor Server app.
using Azure.AI.OpenAI;
using Microsoft.Extensions.AI;
using Sample.Components;
using Syncfusion.Blazor;
using Syncfusion.Blazor.AI;
using System.ClientModel;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalR(o => { o.MaximumReceiveMessageSize = 102400000; });
builder.Services.AddMemoryCache();
string azureOpenAiKey = "api-key";
string azureOpenAiEndpoint = "endpoint URL";
string azureOpenAiModel = "deployment-name";
AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient(new Uri(azureOpenAiEndpoint), new ApiKeyCredential(azureOpenAiKey));
IChatClient azureOpenAiChatClient = azureOpenAIClient.GetChatClient(azureOpenAiModel).AsIChatClient();
builder.Services.AddChatClient(azureOpenAiChatClient);
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();
var app = builder.Build();
....
Here,
- apiKey: “Azure OpenAI API Key”;
- deploymentName: “Azure OpenAI deployment name”;
- endpoint: “Azure OpenAI deployment end point URL”;
For Azure OpenAI, first deploy an Azure OpenAI Service resource and model, then values for apiKey
, deploymentName
and endpoint
will all be provided to you.
To Configure Ollama for Self-Hosted AI Models
To use Ollama for running self-hosted models:
-
Download and install Ollama
Visit Ollama’s official website and install the application appropriate for your operating system. -
Install the desired model from the Ollama library
You can browse and install models from the Ollama Library (e.g., llama2:13b, mistral:7b, etc.).
In Visual Studio, Go to Tools → NuGet Package Manager → Package Manager Console. Run these commands one by one:
Install-Package OllamaSharp -Version 5.3.6
In Visual Studio Code, Open terminal in VS Code. Run these commands:
dotnet add package OllamaSharp --version 5.3.6
Add the following settings to the ~/Program.cs file in your Blazor Server app.
...
var builder = WebApplication.CreateBuilder(args);
// Define the name of the AI model to use from Ollama (e.g., llama2, mistral, etc.)
string aiModel = "llama2";
// Add your local Ollama server URL (e.g., "http://localhost:11434")
IChatClient chatClient = new OllamaApiClient("http://localhost:11434", aiModel);
builder.Services.AddChatClient(chatClient);
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();
var app = builder.Build();
...
Add stylesheet and script resources
The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Include the stylesheet reference in the <head>
section and the script reference at the end of the <body>
in the ~/Components/App.razor file as shown below:
<head>
....
<!-- Syncfusion Blazor Smart PDF Viewer control's theme style sheet -->
<link href="_content/Syncfusion.Blazor.Themes/fluent2.css" rel="stylesheet" />
</head>
<body>
....
<!-- Syncfusion Blazor Smart PDF Viewer control's scripts -->
<script src="_content/Syncfusion.Blazor.SfSmartPdfViewer/scripts/syncfusion-blazor-sfsmartpdfviewer.min.js" type="text/javascript"></script>
</body>
NOTE
Check out the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.
Add Syncfusion® Blazor Smart PDF Viewer component
Add the Syncfusion® Blazor Smart PDF Viewer component in the ~Pages/Home.razor file.
@page "/"
<SfSmartPdfViewer Height="100%" Width="100%" DocumentPath="https://cdn.syncfusion.com/content/pdf/http-succinctly.pdf">
</SfSmartPdfViewer>
- Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. This will render the Syncfusion® Blazor Smart PDF Viewer component in your default web browser.
NOTE