Getting Started with Smart PDF Viewer
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.1.17
Install-Package Syncfusion.Blazor.Themes -Version 31.1.17
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);
builder.Services.AddSignalR(o => { o.MaximumReceiveMessageSize = 102400000; });
builder.Services.AddMemoryCache();
// 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);
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 explore available models from the Ollama Library (e.g., llama2:13b, llama2:7b, mistral:7b, etc.).
To download and run a model (e.g., llama2:7b), use the following command:
ollama run llama2:7b
In Visual Studio, Go to Tools → NuGet Package Manager → Package Manager Console. Run these command:
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.
using Microsoft.Extensions.AI;
using OllamaSharp;
using Syncfusion.Blazor;
using Syncfusion.Blazor.AI;
...
var builder = WebApplication.CreateBuilder(args);
...
builder.Services.AddSyncfusionBlazor();
// Define the name of the AI model to use from Ollama (e.g., llama2:13b, mistral:7b, etc.)
string aiModel = "llama2:7b";
// By default, Ollama runs on port 11434, you can also customize this port manually.
HttpClient httpClient = new HttpClient
{
BaseAddress = new Uri("http://localhost:11434"), // Ollama server address
Timeout = Timeout.InfiniteTimeSpan // Supports extended processing time for AI responses
};
// Initialize the chat client using the Ollama API and the specified model
IChatClient chatClient = new OllamaApiClient(httpClient, aiModel);
builder.Services.AddChatClient(chatClient);
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();
var app = builder.Build();
...
NOTE
Running Ollama locally may lead to slower response times due to system resource usage.
To accommodate this, you can configure the Syncfusion Smart PDF Viewer to disable timeout for AI assist view operations by setting the timeout to 0.
Learn more
To Check the Installed Model and Its Details in Ollama
- To verify which models are currently installed and available on your local Ollama server (example: running on port 11434), run the following command in your terminal or command prompt:
curl http://localhost:11434/api/tags
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