Skip to content

Commit 6f92ead

Browse files
855095-ExceltoPDFElasticBeanstalk
1 parent fbb2cb0 commit 6f92ead

File tree

85 files changed

+74898
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+74898
-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.14.36127.28 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertExceltoPDF", "ConvertExceltoPDF\ConvertExceltoPDF.csproj", "{0D845785-5F70-4B8B-8982-737E5BF58135}"
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+
{0D845785-5F70-4B8B-8982-737E5BF58135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0D845785-5F70-4B8B-8982-737E5BF58135}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0D845785-5F70-4B8B-8982-737E5BF58135}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0D845785-5F70-4B8B-8982-737E5BF58135}.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 = {3599B912-BC41-4D46-BF2C-1F6A12870EF6}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using ConvertExceltoPDF.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Syncfusion.Drawing;
4+
using Syncfusion.Pdf;
5+
using Syncfusion.XlsIO;
6+
using Syncfusion.XlsIO.Implementation;
7+
using Syncfusion.XlsIORenderer;
8+
using System.Diagnostics;
9+
using System.IO;
10+
11+
namespace ConvertExceltoPDF.Controllers
12+
{
13+
public class HomeController : Controller
14+
{
15+
private readonly ILogger<HomeController> _logger;
16+
17+
public HomeController(ILogger<HomeController> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public IActionResult Index()
23+
{
24+
return View();
25+
}
26+
27+
public IActionResult Privacy()
28+
{
29+
return View();
30+
}
31+
32+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
33+
public IActionResult ConvertExceltoPDF()
34+
{
35+
using (ExcelEngine excelEngine = new ExcelEngine())
36+
{
37+
IApplication application = excelEngine.Excel;
38+
application.DefaultVersion = ExcelVersion.Xlsx;
39+
40+
//Initializes the SubstituteFont event to perform font substitution during Excel-to-PDF conversion
41+
application.SubstituteFont += new SubstituteFontEventHandler(SubstituteFont);
42+
43+
FileStream excelStream = new FileStream(@"Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
44+
IWorkbook workbook = application.Workbooks.Open(excelStream);
45+
46+
//Initialize XlsIO renderer.
47+
XlsIORenderer renderer = new XlsIORenderer();
48+
49+
//Convert Excel document into PDF document
50+
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
51+
52+
//Create the MemoryStream to save the converted PDF.
53+
MemoryStream pdfStream = new MemoryStream();
54+
55+
//Save the converted PDF document to MemoryStream.
56+
pdfDocument.Save(pdfStream);
57+
pdfStream.Position = 0;
58+
//Download PDF document in the browser
59+
return File(pdfStream, "application/pdf", "Sample.pdf");
60+
}
61+
}
62+
63+
private static void SubstituteFont(object sender, SubstituteFontEventArgs args)
64+
{
65+
string filePath = string.Empty;
66+
FileStream fileStream = null;
67+
68+
if (args.OriginalFontName == "Calibri")
69+
{
70+
filePath = Path.GetFullPath(@"Data/calibri.ttf");
71+
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
72+
args.AlternateFontStream = fileStream;
73+
}
74+
}
75+
}
76+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.116.1" />
11+
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="29.2.7" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Content Include="Data\**\*">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
</Content>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<None Update="Data\calibri.ttf">
22+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23+
</None>
24+
<None Update="Data\calibrib.ttf">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
<None Update="Data\calibrii.ttf">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</None>
30+
<None Update="Data\calibril.ttf">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
<None Update="Data\calibrili.ttf">
34+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
35+
</None>
36+
<None Update="Data\calibriz.ttf">
37+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
38+
</None>
39+
<None Update="Data\InputTemplate.xlsx">
40+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41+
</None>
42+
</ItemGroup>
43+
44+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)