Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Unified-font-manager/.NET/Dedicated-font-manager.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.37012.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dedicated-font-manager", "Dedicated-font-manager\Dedicated-font-manager.csproj", "{419DDFEB-A2E2-4090-9E1D-0BE6D9EE80AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{419DDFEB-A2E2-4090-9E1D-0BE6D9EE80AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{419DDFEB-A2E2-4090-9E1D-0BE6D9EE80AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{419DDFEB-A2E2-4090-9E1D-0BE6D9EE80AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{419DDFEB-A2E2-4090-9E1D-0BE6D9EE80AC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {75E58B0E-2E19-4599-894D-D6CDD93A3D7C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
using Dedicated_font_manager.Models;
using Microsoft.AspNetCore.Mvc;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer;
using System.Diagnostics;

namespace Dedicated_font_manager.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult OfficeToPDF(string button)
{
if (button == null)
return View("Index");

if (Request.Form.Files != null)
{
if (Request.Form.Files.Count == 0)
{
ViewBag.Message = string.Format("Browse a Word document and then click the button to convert as a PDF document");
return View("Index");
}
// Gets the extension from file.
string extension = Path.GetExtension(Request.Form.Files[0].FileName).ToLower();
string fileName = Path.GetFileNameWithoutExtension(Request.Form.Files[0].FileName);

try
{
PdfDocument pdfDocument = null;
// Switch on file extension to determine conversion method
switch (extension.ToLower())
{
// Word document formats
case ".doc":
case ".docx":
case ".dot":
case ".dotx":
case ".dotm":
case ".docm":
case ".xml":
case ".rtf":
using (MemoryStream inputStream = new MemoryStream())
{
// Copy uploaded file to memory stream
Request.Form.Files[0].CopyTo(inputStream);
inputStream.Position = 0;
// Open and load the Word document
using (WordDocument wordDocument = new WordDocument())
{
// Convert Word document to PDF format
wordDocument.Open(inputStream, Syncfusion.DocIO.FormatType.Automatic);
using (DocIORenderer renderer = new DocIORenderer())
{
pdfDocument = renderer.ConvertToPDF(wordDocument);
}
}
}
break;
// Excel format
case ".xlsx":
case ".xls":
case ".xltx":
case ".xlsm":
case ".csv":
case ".xlsb":
case ".xltm":
using (MemoryStream inputStream = new MemoryStream())
{
// Copy uploaded file to memory stream
Request.Form.Files[0].CopyTo(inputStream);
inputStream.Position = 0;
// Create Excel engine and load workbook
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(inputStream);
// Convert Excel workbook to PDF format
XlsIORenderer renderer = new XlsIORenderer();
pdfDocument = renderer.ConvertToPDF(workbook);
}
}
break;
// PowerPoint format
case ".pptx":
using (MemoryStream inputStream = new MemoryStream())
{
// Copy uploaded file to memory stream
Request.Form.Files[0].CopyTo(inputStream);
inputStream.Position = 0;
// Open PowerPoint presentation and convert to PDF
using (IPresentation pptxDoc = Presentation.Open(inputStream))
{
pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);
}
}
break;
// Invalid file format
default:
ViewBag.Message = "Please choose Word, Excel or PowerPoint document to convert to PDF";
return null;
}
// Save converted PDF and return as downloadable file
if (pdfDocument != null)
{
using (pdfDocument)
{
// Create memory stream to hold the PDF data
MemoryStream pdfStream = new MemoryStream();
// Save the converted PDF to memory stream
pdfDocument.Save(pdfStream);
// Reset stream position to beginning for reading
pdfStream.Position = 0;
// Return PDF as downloadable file to browser
return File(pdfStream, "application/pdf", fileName + ".pdf");
}
}
}
catch (Exception ex)
{
ViewBag.Message = string.Format(ex.Message);
}
}
else
{
ViewBag.Message = string.Format("Browse a Word,Excel or PowerPoint document and then click the button to convert as a PDF document");
}
return View("Index");
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Dedicated_font_manager</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Dedicated_font_manager.Models
{
public class ErrorViewModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
40 changes: 40 additions & 0 deletions Unified-font-manager/.NET/Dedicated-font-manager/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Set FontManager delay at startup (before any conversions happen)
// Default is 30000ms. Adjust based on your conversion workload.
Syncfusion.Drawing.Fonts.FontManager.Delay = 50000;

// Access the application lifetime service
var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();

// Register a callback to run when the app is shutting down
lifetime.ApplicationStopping.Register(() =>
{
Syncfusion.Drawing.Fonts.FontManager.ClearCache();
});

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:62691",
"sslPort": 44377
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5072",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7105;http://localhost:5072",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@{
ViewData["Title"] = "Home Page";
}

@using (Html.BeginForm("OfficeToPDF", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="Common">
<div class="tablediv">
<div class="rowdiv">
<p>This sample illustrates how to convert Word document, Excel and PowerPoint file to PDF using Document SDK.</p>

<p><strong>Font Manager:</strong> A unified font-caching system that optimizes memory usage across all document conversion libraries (Word-to-PDF, Excel-to-PDF, PowerPoint-to-PDF, and PDF processing).
This centralized font management significantly optimizes memory usage in multi-threaded conversions by preventing redundant font loading.
</p>
</div>

<div class="rowdiv" style="border-width: 0.5px; border-style: solid; border-color: lightgray; padding: 1px 5px 7px 5px; margin-top: 8px;">
Click the button to view the resultant PDF document being converted using Document SDK.
Please note that a PDF viewer is required to view the resultant PDF.

<div class="rowdiv" style="margin-top: 10px">
<div class="celldiv">
Select Document :
@Html.TextBox("file", null, new { type = "file", accept = ".doc,.docx,.rtf,.dot,.dotm,.dotx,.docm,.xml,.xlsx,.xls,.xltx,.xlsm,.csv,.xlsb,.xltm,.pptx" })
<br />
</div>

<div class="rowdiv" style="margin-top: 8px">
<input class="buttonStyle" type="submit" value="Convert to PDF" name="button" style="width:150px;height:27px" />
<br />
<div class="text-danger">
@ViewBag.Message
</div>
</div>
</div>
</div>
</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
Loading
Loading