Skip to content

Commit 987ac53

Browse files
Merge pull request #297 from Suriya-Balamurugan/main
Update the AWS Lambda with latest solution of .NET80
2 parents 8ba2e04 + e8828d1 commit 987ac53

File tree

16 files changed

+87
-50
lines changed

16 files changed

+87
-50
lines changed

Word-to-Image-conversion/Convert-Word-to-image/AWS/AWS_Elastic_Beanstalk/Convert-Word-Document-to-Image/Convert-Word-Document-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.DocIORenderer.Net.Core" Version="*" />
1313
</ItemGroup>
1414

Word-to-Image-conversion/Convert-Word-to-image/AWS/AWS_Lambda/Convert-Word-Document-to-Image/Convert-Word-Document-to-Image.csproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<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,20 @@
1717
<EmbeddedResource Include="Data\Input.docx">
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</EmbeddedResource>
20+
<EmbeddedResource Include="Data\calibri.ttf">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</EmbeddedResource>
23+
<EmbeddedResource Include="Data\calibrib.ttf">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</EmbeddedResource>
26+
<EmbeddedResource Include="Data\times.ttf">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</EmbeddedResource>
2029
</ItemGroup>
2130
<ItemGroup>
2231
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
2332
<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" />
33+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
2634
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
2735
</ItemGroup>
2836
</Project>

Word-to-Image-conversion/Convert-Word-to-image/AWS/AWS_Lambda/Convert-Word-Document-to-Image/Function.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Syncfusion.DocIO;
33
using Syncfusion.DocIO.DLS;
44
using Syncfusion.DocIORenderer;
5+
using Syncfusion.Drawing;
56

67
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
78
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
@@ -19,18 +20,35 @@ public class Function
1920
/// <returns></returns>
2021
public string FunctionHandler(string input, ILambdaContext context)
2122
{
23+
//Path to the original library file.
24+
string originalLibraryPath = "/lib64/libdl.so.2";
25+
26+
//Path to the symbolic link where the library will be copied.
27+
string symlinkLibraryPath = "/tmp/libdl.so";
28+
29+
//Check if the original library file exists.
30+
if (File.Exists(originalLibraryPath))
31+
{
32+
//Copy the original library file to the symbolic link path, overwriting if it already exists.
33+
File.Copy(originalLibraryPath, symlinkLibraryPath, true);
34+
}
35+
2236
string filePath = Path.GetFullPath(@"Data/Input.docx");
2337
//Open the file as Stream.
2438
using (FileStream docStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
2539
{
2640
//Loads file stream into Word document.
2741
using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Docx))
2842
{
43+
//Hooks the font substitution event.
44+
wordDocument.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
2945
//Instantiation of DocIORenderer.
3046
using (DocIORenderer render = new DocIORenderer())
3147
{
3248
//Convert the first page of the Word document into an image.
3349
Stream imageStream = wordDocument.RenderAsImages(0, ExportImageFormat.Jpeg);
50+
//Unhooks the font substitution event after converting to image.
51+
wordDocument.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
3452
//Reset the stream position.
3553
imageStream.Position = 0;
3654
//Save the image file into stream.
@@ -41,4 +59,15 @@ public string FunctionHandler(string input, ILambdaContext context)
4159
}
4260
}
4361
}
62+
63+
//Set the alternate font when a specified font is not installed in the production environment.
64+
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
65+
{
66+
if (args.OriginalFontName == "Calibri" && args.FontStyle == FontStyle.Regular)
67+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/calibri.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
68+
else if (args.OriginalFontName == "Calibri" && args.FontStyle == FontStyle.Bold)
69+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/calibrib.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
70+
else
71+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/times.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
72+
}
4473
}

Word-to-Image-conversion/Convert-Word-to-image/AWS/AWS_Lambda/Convert-Word-Document-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
}

Word-to-Image-conversion/Convert-Word-to-image/AWS/AWS_Lambda/Convert-Word-Document-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" : "venkat",
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-Word-Document-to-Image::Convert_Word_Document_to_Image.Function::FunctionHandler",
17-
"framework" : "net6.0",
17+
"framework" : "net8.0",
1818
"function-name" : "ConvertWordtoImage",
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" : "",
24+
"environment-variables" : "\"LD_LIBRARY_PATH\"=\"/var/task:/tmp:/lib64:/usr/lib64\"",
2525
"image-tag" : "",
2626
"function-description" : ""
2727
}

Word-to-Image-conversion/Convert-Word-to-image/GCP/Google_App_Engine/Convert-Word-Document-to-Image/Convert-Word-Document-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.DocIORenderer.Net.Core" Version="*" />
2020
</ItemGroup>
2121
</Project>

0 commit comments

Comments
 (0)