Skip to content
Open
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,170 @@
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 WordToPDF(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);

// Compares extension with supported extensions.
if (extension == ".doc" || extension == ".docx" || extension == ".dot" || extension == ".dotx" || extension == ".dotm" || extension == ".docm"
|| extension == ".xml" || extension == ".rtf")
{
try
{
MemoryStream outputStream = new MemoryStream();
//Open the Word document file stream.
using (MemoryStream inputStream = new MemoryStream())
{
Request.Form.Files[0].CopyTo(inputStream);
inputStream.Position = 0;
//Loads an existing Word document.
using (WordDocument wordDocument = new WordDocument())
{
wordDocument.Open(inputStream, Syncfusion.DocIO.FormatType.Automatic);
//Creates an instance of DocIORenderer.
using (DocIORenderer renderer = new DocIORenderer())
{
//Converts Word document into PDF document.
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
{
pdfDocument.Save(outputStream);
}
}
}
}
outputStream.Position = 0;
return File(outputStream, "application/pdf", fileName + ".pdf");
}
catch (Exception ex)
{
ViewBag.Message = string.Format(ex.Message);
//ViewBag.Message = string.Format("The input document could not be processed completely, Could you please email the document to support@syncfusion.com for troubleshooting.");
}
}
else if (extension == ".xlsx")
{
try
{
using (MemoryStream inputStream = new MemoryStream())
{
Request.Form.Files[0].CopyTo(inputStream);
inputStream.Position = 0;
//Loads an existing Excel document.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//Open the Excel document file stream.
IWorkbook workbook = application.Workbooks.Open(inputStream);
//Initialize XlsIO renderer.
XlsIORenderer renderer = new XlsIORenderer();
//Convert Excel document into PDF document
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
//Create the MemoryStream to save the converted PDF.
MemoryStream pdfStream = new MemoryStream();
//Save the converted PDF document to MemoryStream.
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;

//Download PDF document in the browser.
return File(pdfStream, "application/pdf", "Sample.pdf");
}
}

}
catch (Exception ex)
{
ViewBag.Message = string.Format(ex.Message);
}

}
else if (extension == ".pptx")
{
try
{
using (MemoryStream inputStream = new MemoryStream())
{
Request.Form.Files[0].CopyTo(inputStream);
inputStream.Position = 0;
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(inputStream))
{
//Convert the PowerPoint presentation to PDF document.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
{
//Create the MemoryStream to save the converted PDF.
MemoryStream pdfStream = new MemoryStream();
//Save the converted PDF document to MemoryStream.
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
//Download PDF document in the browser.
return File(pdfStream, "application/pdf", "Sample.pdf");
}
}
}
}
catch (Exception ex)
{
ViewBag.Message = string.Format(ex.Message);
}

}
else
{
ViewBag.Message = string.Format("Please choose Word, Excel or PowerPoint document to convert to PDF");
}
}
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,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</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,36 @@
@{
ViewData["Title"] = "Home Page";
}

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