Skip to content

Commit

Permalink
Merge branch 'SyncfusionExamples:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DharanitharanA authored Nov 18, 2024
2 parents 9604fe8 + 7491fe5 commit 650e259
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -17,12 +17,17 @@
<EmbeddedResource Include="Data\Input.pptx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\calibri.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\times.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Amazon.Lambda.Core;
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
using Syncfusion.Drawing;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

Expand All @@ -17,14 +19,31 @@ public class Function
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
//Path to the original library file.
string originalLibraryPath = "/lib64/libdl.so.2";

//Path to the symbolic link where the library will be copied.
string symlinkLibraryPath = "/tmp/libdl.so";

//Check if the original library file exists.
if (File.Exists(originalLibraryPath))
{
//Copy the original library file to the symbolic link path, overwriting if it already exists.
File.Copy(originalLibraryPath, symlinkLibraryPath, true);
}

string filePath = Path.GetFullPath(@"Data/Input.pptx");
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(filePath))
{
//Hooks the font substitution event.
pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
//Initialize the PresentationRenderer to perform image conversion.
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Convert PowerPoint slide to image as stream.
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
//Unhooks the font substitution event after converting to image file.
pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
//Reset the stream position.
stream.Position = 0;
// Create a memory stream to save the image file.
Expand All @@ -33,4 +52,13 @@ public string FunctionHandler(string input, ILambdaContext context)
return Convert.ToBase64String(memoryStream.ToArray());
}
}

//Set the alternate font when a specified font is not installed in the production environment.
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
{
if (args.OriginalFontName == "Calibri" && args.FontStyle == FontStyle.Regular)
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/calibri.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
else
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/times.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile" : "default",
"profile" : "AWSLAMBDA",
"region" : "us-east-1",
"configuration" : "Release",
"function-architecture" : "x86_64",
"function-runtime" : "dotnet6",
"function-memory-size" : 256,
"function-runtime" : "dotnet8",
"function-memory-size" : 640,
"function-timeout" : 30,
"function-handler" : "Convert-PowerPoint-Presentation-to-Image::Convert_PowerPoint_Presentation_to_Image.Function::FunctionHandler",
"framework" : "net6.0",
"framework" : "net8.0",
"function-name" : "PPTXtoImageConversion",
"function-description" : "",
"package-type" : "Zip",
"function-role" : "arn:aws:iam::142887710098:role/LambdaRole",
"function-role" : "arn:aws:iam::142887710098:role/ck_lambda_basic_execution",
"function-subnets" : "",
"function-security-groups" : "",
"tracing-mode" : "PassThrough",
"environment-variables" : "",
"environment-variables" : "\"LD_LIBRARY_PATH\"=\"/var/task:/tmp:/lib64:/usr/lib64\"",
"image-tag" : ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.2" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -17,12 +17,17 @@
<EmbeddedResource Include="Data\Input.pptx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\calibri.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\times.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
using System.IO;
using Syncfusion.Drawing;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
Expand All @@ -20,24 +21,50 @@ public class Function
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
//Path to the original library file.
string originalLibraryPath = "/lib64/libdl.so.2";

//Path to the symbolic link where the library will be copied.
string symlinkLibraryPath = "/tmp/libdl.so";

//Check if the original library file exists.
if (File.Exists(originalLibraryPath))
{
//Copy the original library file to the symbolic link path, overwriting if it already exists.
File.Copy(originalLibraryPath, symlinkLibraryPath, true);
}

string filePath = Path.GetFullPath(@"Data/Input.pptx");
//Open the file as Stream
using (FileStream fileStreamInput = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//Hooks the font substitution event.
pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
//Convert the PowerPoint document 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);
//Unhooks the font substitution event after converting to PDF.
pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
pdfStream.Position = 0;
return Convert.ToBase64String(pdfStream.ToArray());
}
}
}
}

//Set the alternate font when a specified font is not installed in the production environment.
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
{
if (args.OriginalFontName == "Calibri" && args.FontStyle == FontStyle.Regular)
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/calibri.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
else
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/times.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile" : "default",
"profile" : "AWSLAMBDA",
"region" : "us-east-1",
"configuration" : "Release",
"function-architecture" : "x86_64",
"function-runtime" : "dotnet6",
"function-memory-size" : 256,
"function-runtime" : "dotnet8",
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "Convert-PowerPoint-Presentation-to-PDF::Convert_PowerPoint_Presentation_to_PDF.Function::FunctionHandler",
"framework" : "net6.0",
"framework" : "net8.0",
"function-name" : "PPTXtoPDF",
"package-type" : "Zip",
"function-role" : "arn:aws:iam::142887710098:role/LambdaRole",
"function-role" : "arn:aws:iam::142887710098:role/ck_lambda_basic_execution",
"function-subnets" : "",
"function-security-groups" : "",
"tracing-mode" : "PassThrough",
"environment-variables" : "",
"image-tag" : ""
"environment-variables" : "\"LD_LIBRARY_PATH\"=\"/var/task:/tmp:/lib64:/usr/lib64\"",
"image-tag" : "",
"function-description" : ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ static void Main(string[] args)
var responseText = serilizer.Deserialize(reader);
//Convert Base64String into PDF document.
byte[] bytes = Convert.FromBase64String(responseText.ToString());
FileStream fileStream = new FileStream("Sample.Pdf", FileMode.Create);
FileStream fileStream = new FileStream("Sample.pdf", FileMode.Create);
BinaryWriter writer = new BinaryWriter(fileStream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
System.Diagnostics.Process.Start("Sample.Pdf");
System.Diagnostics.Process.Start("Sample.pdf");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.2" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>
</Project>

0 comments on commit 650e259

Please sign in to comment.