Skip to content

Commit e08833d

Browse files
authored
Merge pull request #44 from SyncfusionExamples/EJ2-931795-loadPdftoServer
931795: Sample on How to Load PDF to Server Side PDF Viewer
2 parents a31c2e3 + 8c05f50 commit e08833d

24 files changed

+471
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33403.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Load-PDF-to-Server-Side-PDF-Viewer", "Load-PDF-to-Server-Side-PDF-Viewer\Load-PDF-to-Server-Side-PDF-Viewer.csproj", "{5FF8C787-D789-484A-9124-6D39167CC7E9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5FF8C787-D789-484A-9124-6D39167CC7E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5FF8C787-D789-484A-9124-6D39167CC7E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5FF8C787-D789-484A-9124-6D39167CC7E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5FF8C787-D789-484A-9124-6D39167CC7E9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E1D8E12F-9CC3-44F5-B57F-184524C265B7}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using CoreSample.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Diagnostics;
4+
5+
namespace CoreSample.Controllers
6+
{
7+
public class HomeController : Controller
8+
{
9+
private readonly ILogger<HomeController> _logger;
10+
11+
public HomeController(ILogger<HomeController> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
public IActionResult Index()
17+
{
18+
return View();
19+
}
20+
21+
public IActionResult Privacy()
22+
{
23+
return View();
24+
}
25+
26+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
27+
public IActionResult Error()
28+
{
29+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Caching.Memory;
3+
using Newtonsoft.Json;
4+
using Syncfusion.EJ2.PdfViewer;
5+
using System.Net;
6+
using System.Reflection;
7+
using System.Runtime.InteropServices.JavaScript;
8+
using System.Text.Json.Nodes;
9+
10+
namespace CoreSample.Controllers
11+
{
12+
public class PdfViewerController : Controller
13+
{
14+
private IWebHostEnvironment _hostingEnvironment;
15+
//Initialize the memory cache object
16+
public IMemoryCache _cache;
17+
public PdfViewerController(IWebHostEnvironment hostingEnvironment, IMemoryCache cache)
18+
{
19+
_hostingEnvironment = hostingEnvironment;
20+
_cache = cache;
21+
Console.WriteLine("PdfViewerController initialized");
22+
}
23+
public IActionResult Index()
24+
{
25+
return View();
26+
}
27+
28+
[HttpGet]
29+
//Get action for obtaing the byte array of the PDF document
30+
public IActionResult GetPDFByte(string fileName)
31+
{
32+
string documentPath = GetDocumentPath(fileName);
33+
// Read the file content into a byte array
34+
byte[] fileBytes = System.IO.File.ReadAllBytes(documentPath);
35+
36+
// Return the byte array as a file
37+
return File(fileBytes, "application/pdf", fileName);
38+
}
39+
40+
//Gets the path of the PDF document
41+
private string GetDocumentPath(string document)
42+
{
43+
string documentPath = string.Empty;
44+
if (!System.IO.File.Exists(document))
45+
{
46+
var path = _hostingEnvironment.ContentRootPath;
47+
if (System.IO.File.Exists(path + "/Data/" + document))
48+
documentPath = path + "/Data/" + document;
49+
}
50+
else
51+
{
52+
documentPath = document;
53+
}
54+
Console.WriteLine(documentPath);
55+
return documentPath;
56+
}
57+
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.13" />
11+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="27.2.5" />
12+
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="27.2.5" />
13+
<PackageReference Include="Syncfusion.EJ2.WordEditor.AspNet.Core" Version="27.2.5" />
14+
</ItemGroup>
15+
16+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
5+
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
6+
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
7+
</PropertyGroup>
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
10+
</PropertyGroup>
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Load-PDF-to-Server-Side-PDF-Viewer", "Load-PDF-to-Server-Side-PDF-Viewer.csproj", "{26C6026E-0610-419D-BCEB-DED8AC494AA4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{26C6026E-0610-419D-BCEB-DED8AC494AA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{26C6026E-0610-419D-BCEB-DED8AC494AA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{26C6026E-0610-419D-BCEB-DED8AC494AA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{26C6026E-0610-419D-BCEB-DED8AC494AA4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B1FEF192-1C54-4ADC-B38A-8179031CB211}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CoreSample.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}

0 commit comments

Comments
 (0)