Skip to content

Commit 7491fe5

Browse files
Merge pull request #95 from Suriya-Balamurugan/master
Update the AWS Lambda with latest solution of .NET80
2 parents 734ccf0 + 358cfe5 commit 7491fe5

File tree

19 files changed

+97
-31
lines changed

19 files changed

+97
-31
lines changed

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/AWS/AWS_Elastic_Beanstalk/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
11+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
1212
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
1313
</ItemGroup>
1414

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@@ -17,12 +17,17 @@
1717
<EmbeddedResource Include="Data\Input.pptx">
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</EmbeddedResource>
20+
<EmbeddedResource Include="Data\calibri.ttf">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</EmbeddedResource>
23+
<EmbeddedResource Include="Data\times.ttf">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</EmbeddedResource>
2026
</ItemGroup>
2127
<ItemGroup>
2228
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
2329
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
24-
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
25-
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
30+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
2631
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
2732
</ItemGroup>
2833
</Project>

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-Image/Function.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Amazon.Lambda.Core;
22
using Syncfusion.Presentation;
33
using Syncfusion.PresentationRenderer;
4+
using Syncfusion.Drawing;
5+
46
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
57
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
68

@@ -17,14 +19,31 @@ public class Function
1719
/// <returns></returns>
1820
public string FunctionHandler(string input, ILambdaContext context)
1921
{
22+
//Path to the original library file.
23+
string originalLibraryPath = "/lib64/libdl.so.2";
24+
25+
//Path to the symbolic link where the library will be copied.
26+
string symlinkLibraryPath = "/tmp/libdl.so";
27+
28+
//Check if the original library file exists.
29+
if (File.Exists(originalLibraryPath))
30+
{
31+
//Copy the original library file to the symbolic link path, overwriting if it already exists.
32+
File.Copy(originalLibraryPath, symlinkLibraryPath, true);
33+
}
34+
2035
string filePath = Path.GetFullPath(@"Data/Input.pptx");
2136
//Open the existing PowerPoint presentation with loaded stream.
2237
using (IPresentation pptxDoc = Presentation.Open(filePath))
2338
{
39+
//Hooks the font substitution event.
40+
pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
2441
//Initialize the PresentationRenderer to perform image conversion.
2542
pptxDoc.PresentationRenderer = new PresentationRenderer();
2643
//Convert PowerPoint slide to image as stream.
2744
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
45+
//Unhooks the font substitution event after converting to image file.
46+
pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
2847
//Reset the stream position.
2948
stream.Position = 0;
3049
// Create a memory stream to save the image file.
@@ -33,4 +52,13 @@ public string FunctionHandler(string input, ILambdaContext context)
3352
return Convert.ToBase64String(memoryStream.ToArray());
3453
}
3554
}
55+
56+
//Set the alternate font when a specified font is not installed in the production environment.
57+
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
58+
{
59+
if (args.OriginalFontName == "Calibri" && args.FontStyle == FontStyle.Regular)
60+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/calibri.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
61+
else
62+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/times.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
63+
}
3664
}

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-Image/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"Mock Lambda Test Tool": {
44
"commandName": "Executable",
55
"commandLineArgs": "--port 5050",
6-
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
7-
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
6+
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
7+
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
88
}
99
}
1010
}

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-Image/aws-lambda-tools-defaults.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
"dotnet lambda help",
77
"All the command line options for the Lambda command can be specified in this file."
88
],
9-
"profile" : "default",
9+
"profile" : "AWSLAMBDA",
1010
"region" : "us-east-1",
1111
"configuration" : "Release",
1212
"function-architecture" : "x86_64",
13-
"function-runtime" : "dotnet6",
14-
"function-memory-size" : 256,
13+
"function-runtime" : "dotnet8",
14+
"function-memory-size" : 640,
1515
"function-timeout" : 30,
1616
"function-handler" : "Convert-PowerPoint-Presentation-to-Image::Convert_PowerPoint_Presentation_to_Image.Function::FunctionHandler",
17-
"framework" : "net6.0",
17+
"framework" : "net8.0",
1818
"function-name" : "PPTXtoImageConversion",
1919
"function-description" : "",
2020
"package-type" : "Zip",
21-
"function-role" : "arn:aws:iam::142887710098:role/LambdaRole",
21+
"function-role" : "arn:aws:iam::142887710098:role/ck_lambda_basic_execution",
2222
"function-subnets" : "",
2323
"function-security-groups" : "",
2424
"tracing-mode" : "PassThrough",
25-
"environment-variables" : "",
25+
"environment-variables" : "\"LD_LIBRARY_PATH\"=\"/var/task:/tmp:/lib64:/usr/lib64\"",
2626
"image-tag" : ""
2727
}

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/GCP/Google_App_Engine/Convert-PPTX-to-image/Convert-PPTX-to-image.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
18-
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
17+
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
18+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.2" />
1919
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
2020
</ItemGroup>
2121
</Project>

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Elastic_Beanstalk/Convert-PowerPoint-Presentation-to-PDF/Convert-PowerPoint-Presentation-to-PDF.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
11+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
1212
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
1313
</ItemGroup>
1414

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Convert-PowerPoint-Presentation-to-PDF.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@@ -17,12 +17,17 @@
1717
<EmbeddedResource Include="Data\Input.pptx">
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</EmbeddedResource>
20+
<EmbeddedResource Include="Data\calibri.ttf">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</EmbeddedResource>
23+
<EmbeddedResource Include="Data\times.ttf">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</EmbeddedResource>
2026
</ItemGroup>
2127
<ItemGroup>
2228
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
2329
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
24-
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
25-
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
30+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
2631
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
2732
</ItemGroup>
2833
</Project>

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Function.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Syncfusion.Presentation;
44
using Syncfusion.PresentationRenderer;
55
using System.IO;
6+
using Syncfusion.Drawing;
67

78
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
89
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
@@ -20,24 +21,50 @@ public class Function
2021
/// <returns></returns>
2122
public string FunctionHandler(string input, ILambdaContext context)
2223
{
24+
//Path to the original library file.
25+
string originalLibraryPath = "/lib64/libdl.so.2";
26+
27+
//Path to the symbolic link where the library will be copied.
28+
string symlinkLibraryPath = "/tmp/libdl.so";
29+
30+
//Check if the original library file exists.
31+
if (File.Exists(originalLibraryPath))
32+
{
33+
//Copy the original library file to the symbolic link path, overwriting if it already exists.
34+
File.Copy(originalLibraryPath, symlinkLibraryPath, true);
35+
}
36+
2337
string filePath = Path.GetFullPath(@"Data/Input.pptx");
2438
//Open the file as Stream
2539
using (FileStream fileStreamInput = new FileStream(filePath, FileMode.Open, FileAccess.Read))
2640
{
2741
//Open the existing PowerPoint presentation with loaded stream.
2842
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
2943
{
44+
//Hooks the font substitution event.
45+
pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
3046
//Convert the PowerPoint document to PDF document.
3147
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
3248
{
3349
//Create the MemoryStream to save the converted PDF.
3450
MemoryStream pdfStream = new MemoryStream();
3551
//Save the converted PDF document to MemoryStream.
3652
pdfDocument.Save(pdfStream);
53+
//Unhooks the font substitution event after converting to PDF.
54+
pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
3755
pdfStream.Position = 0;
3856
return Convert.ToBase64String(pdfStream.ToArray());
3957
}
4058
}
4159
}
4260
}
61+
62+
//Set the alternate font when a specified font is not installed in the production environment.
63+
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
64+
{
65+
if (args.OriginalFontName == "Calibri" && args.FontStyle == FontStyle.Regular)
66+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/calibri.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
67+
else
68+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/times.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
69+
}
4370
}

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"Mock Lambda Test Tool": {
44
"commandName": "Executable",
55
"commandLineArgs": "--port 5050",
6-
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
7-
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
6+
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
7+
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
88
}
99
}
1010
}

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/aws-lambda-tools-defaults.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
"dotnet lambda help",
77
"All the command line options for the Lambda command can be specified in this file."
88
],
9-
"profile" : "default",
9+
"profile" : "AWSLAMBDA",
1010
"region" : "us-east-1",
1111
"configuration" : "Release",
1212
"function-architecture" : "x86_64",
13-
"function-runtime" : "dotnet6",
14-
"function-memory-size" : 256,
13+
"function-runtime" : "dotnet8",
14+
"function-memory-size" : 512,
1515
"function-timeout" : 30,
1616
"function-handler" : "Convert-PowerPoint-Presentation-to-PDF::Convert_PowerPoint_Presentation_to_PDF.Function::FunctionHandler",
17-
"framework" : "net6.0",
17+
"framework" : "net8.0",
1818
"function-name" : "PPTXtoPDF",
1919
"package-type" : "Zip",
20-
"function-role" : "arn:aws:iam::142887710098:role/LambdaRole",
20+
"function-role" : "arn:aws:iam::142887710098:role/ck_lambda_basic_execution",
2121
"function-subnets" : "",
2222
"function-security-groups" : "",
2323
"tracing-mode" : "PassThrough",
24-
"environment-variables" : "",
25-
"image-tag" : ""
24+
"environment-variables" : "\"LD_LIBRARY_PATH\"=\"/var/task:/tmp:/lib64:/usr/lib64\"",
25+
"image-tag" : "",
26+
"function-description" : ""
2627
}

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/Console_Application/PPTXtoPDF/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ static void Main(string[] args)
3333
var responseText = serilizer.Deserialize(reader);
3434
//Convert Base64String into PDF document.
3535
byte[] bytes = Convert.FromBase64String(responseText.ToString());
36-
FileStream fileStream = new FileStream("Sample.Pdf", FileMode.Create);
36+
FileStream fileStream = new FileStream("Sample.pdf", FileMode.Create);
3737
BinaryWriter writer = new BinaryWriter(fileStream);
3838
writer.Write(bytes, 0, bytes.Length);
3939
writer.Close();
40-
System.Diagnostics.Process.Start("Sample.Pdf");
40+
System.Diagnostics.Process.Start("Sample.pdf");
4141
}
4242
}
4343
}

PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/GCP/Google_App_Engine/Convert-PPTX-to-PDF/Convert-PPTX-to-PDF.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
18-
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
17+
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
18+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.2" />
1919
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
2020
</ItemGroup>
2121
</Project>

0 commit comments

Comments
 (0)