Add web image viewer to a "React and ASP.NET Core" application
In This Topic
This tutorial shows how to create a blank "React and ASP.NET Core" application in Visual Studio .NET 2026 and add image viewer to "React and ASP.NET Core" application.
Here are steps, which must be done:
-
Create a blank "React and ASP.NET Core" application.
-
Open Visual Studio .NET 2026 and create a new application of "React and ASP.NET Core" type:
-
Configure the application to use .NET 10.0:
-
"ReactApp1.Server" project: Add references to the Vintasoft nuget-packages to "ReactApp1.Server" project.
Add references to the nuget-packages "Vintasoft.Imaging.Annotation.AspNetCore.ApiControllers" and "Vintasoft.Imaging.Pdf" to the "ReactApp1.Server" project. Other necessary nuget-packages will be added automatically.
-
"ReactApp1.Server" project: Specify drawing engine, which should be used by VintaSoft Imaging .NET SDK for drawing of 2D graphics.
If "ReactApp1.Server" project must be used in Windows or Linux, SkiaSharp drawing engine should be used.
If "ReactApp1.Server" project must be used in Windows only, System.Drawing or SkiaSharp drawing engine should be used.
Here are steps, which should be made for using SkiaSharp engine:
-
Add reference to the "Vintasoft.Imaging.Drawing.SkiaSharp" nuget-package. Reference to the "SkiaSharp" nuget-package version 3.119.0 will be added automatically.
- Open "Program.cs" file in "ReactApp1.Server" project, add code line "Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();" at the beginning of file - added code specifies that VintaSoft Imaging .NET SDK should use SkiaSharp library for drawing of 2D graphics.
Here are steps, which should be made for using System.Drawing engine:
-
Add reference to the "Vintasoft.Imaging.Gdi" nuget-package.
- Open "Program.cs" file in "ReactApp1.Server" project, add code line "Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();" at the beginning of file - added code specifies that VintaSoft Imaging .NET SDK should use System.Drawing library for drawing of 2D graphics.
-
"ReactApp1.Server" project: Create web services, which allow to upload/download file, manage image collection, get information about images, get thumbnails and render image tiles.
-
Create web service that allows to upload/download file
-
Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
-
Select "Empty API controller" template, set the controller name to the "MyVintasoftFileApiController" and press the "Add" button
-
Specify that MyVintasoftFileApiController class is derived from Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftFileApiController class
Here are source codes of MyVintasoftFileApiController class:
namespace AngularApp1.Server.Controllers
{
public class MyVintasoftFileApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftFileApiController
{
public MyVintasoftFileApiController(IWebHostEnvironment hostingEnvironment)
: base(hostingEnvironment)
{
}
}
}
-
Create web service that allows to manage image collection
-
Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
-
Select "Empty API controller" template, set the controller name to the "MyVintasoftImageCollectionApiController" and press the "Add" button
-
Specify that MyVintasoftImageCollectionApiController class is derived from Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageCollectionApiController class
Here are source codes of MyVintasoftImageCollectionApiController class:
namespace AngularApp1.Server.Controllers
{
public class MyVintasoftImageCollectionApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageCollectionApiController
{
public MyVintasoftImageCollectionApiController(IWebHostEnvironment hostingEnvironment)
: base(hostingEnvironment)
{
}
}
}
-
Create web service that allows to get information about images, get thumbnails and render image tiles
-
Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
-
Select "Empty API controller" template, set the controller name to the "MyVintasoftImageApiController" and press the "Add" button
-
Specify that MyVintasoftImageApiController class is derived from Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageApiController class
Here are source codes of MyVintasoftImageApiController class:
namespace AngularApp1.Server.Controllers
{
public class MyVintasoftImageApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageApiController
{
public MyVintasoftImageApiController(IWebHostEnvironment hostingEnvironment)
: base(hostingEnvironment)
{
}
}
}
-
"ReactApp1.Server" project: Copy the default test PDF document to a server side.
- Create folder "UploadedImageFiles\SessionID" in "ReactApp1.Server" project and copy test PDF document "<SdkInstallPath>\VintaSoft\Imaging .NET 15.0\Examples\ASP.NET Core\CSharp\AspNetCoreImagingDemo\wwwroot\UploadedImageFiles\VintasoftImagingDemo.pdf" to the folder. This document will be displayed in document viewer.
-
Delete files, which are not necessary in this tutorial.
Delete files "WeatherForecast.cs" and "Controllers\WeatherForecastController.cs" in "ReactApp1.Server" project - the WeatherForecast Web API controller is not necessary in this demo.
Compile the solution for restoring TypeScript-dependencies in "reactapp1.client" project.
-
"reactapp1.client" project: Add JavaScript files to the "reactapp1.client" project.
-
Copy Vintasoft.Shared.js and Vintasoft.Imaging.js files from "<InstallPath>\VintaSoft Imaging .NET 15.0\Bin\JavaScript\" folder into "public\" folder.
-
Add references to Vintasoft JavaScript files to the header of "index.html" file:
Here are source codes of "index.html" file:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>reactapp1.client</title>
<script src="Vintasoft.Shared.js" type="text/javascript"></script>
<script src="Vintasoft.Imaging.js" type="text/javascript"></script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
-
Add CSS-styles for this demo to the "src\App.css" file:
Here are source codes of "App.css" file:
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
.imageViewerDemoContainer {
display: flex;
}
.thumbnailViewerContainer {
width: 200px;
height: 800px;
}
.imageViewerContainer {
width: 1200px;
height: 800px;
}
-
"reactapp1.client" project: Create React-component that displays image viewer.
-
Open "src\App.jsx" file in "reactapp1.client" project, clear the file, add code of "App" and "__init" functions. "App" function returns HTML markup (page header and DIV-elements for web image viewer and web thumbnail viewer). "__init" function initializes the application and creates web image viewer and web thumbnail viewer.
Here is code of "src\App.jsx" file:
import './App.css'
function App() {
return (
<>
<h1>VintaSoft Image Viewer Demo (React.js + ASP.NET Core)</h1>
<div className="imageViewerDemoContainer">
<div id="WebThumbnailViewer1Div" className="thumbnailViewerContainer"></div>
<div id="WebImageViewer1Div" className="imageViewerContainer"></div>
</div>
<script>{setTimeout(__init, 10)}</script>
</>
)
}
/**
* Initializes application.
*/
function __init() {
var Vintasoft = window.Vintasoft;
// set the session identifier
Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
// specify web services, which should be used by Vintasoft Web Document Viewer
Vintasoft.Shared.WebServiceJS.defaultFileService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/MyVintasoftFileApi");
Vintasoft.Shared.WebServiceJS.defaultImageCollectionService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/MyVintasoftImageCollectionApi");
Vintasoft.Shared.WebServiceJS.defaultImageService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/MyVintasoftImageApi");
// create thumbnail viewer
var thumbnailViewer = new Vintasoft.Imaging.UI.WebThumbnailViewerJS("WebThumbnailViewer1Div");
// specify that thumbnail viewer should not cache thumbnails on server side
thumbnailViewer.set_UseCache(false);
// create image viewer
var imageViewer = new Vintasoft.Imaging.UI.WebImageViewerJS("WebImageViewer1Div");
// specify that image viewer should not cache image tiles on server side
imageViewer.set_UseCache(false);
// specify that image viewer depends from thumbnail viewer
imageViewer.set_MasterViewer(thumbnailViewer);
// open file from session folder and add images from file to the image viewer
imageViewer.get_Images().openFile("VintasoftImagingDemo.pdf");
}
export default App
-
Open "vite.config.js" file in "reactapp1.client" project and specify that React.js aplication can have access to the ASP.NET Core Web API controller "/vintasoft/api/" in "ReactApp1.Server" project:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
const target = 'https://localhost:7109';
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server: {
proxy: {
'^/vintasoft/api/': {
target,
secure: false
}
},
port: 7109
}
})
-
Run "React and ASP.NET Core" application and see the result.