-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/SyncfusionExamples/XlsIO-…
…Examples into 842237-Google-App-Engine
- Loading branch information
Showing
37 changed files
with
1,416 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Getting Started/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.7.34202.233 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Convert-Excel-to-PDF", "Convert-Excel-to-PDF\Convert-Excel-to-PDF.csproj", "{295165D4-3BDB-45E4-A774-522E24975473}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{295165D4-3BDB-45E4-A774-522E24975473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{295165D4-3BDB-45E4-A774-522E24975473}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{295165D4-3BDB-45E4-A774-522E24975473}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{295165D4-3BDB-45E4-A774-522E24975473}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {8E30ABC3-6970-4FA5-A64F-C532FD607D69} | ||
EndGlobalSection | ||
EndGlobal |
28 changes: 28 additions & 0 deletions
28
...rted/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF/Convert-Excel-to-PDF.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. --> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
<!-- Generate ready to run images during publishing to improve cold start time. --> | ||
<PublishReadyToRun>true</PublishReadyToRun> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Remove="InputTemplate.xlsx" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="InputTemplate.xlsx"> | ||
<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="Syncfusion.XlsIORenderer.Net.Core" Version="23.1.42" /> | ||
</ItemGroup> | ||
</Project> |
Binary file added
BIN
+12 KB
... Started/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF/Data/InputTemplate.xlsx
Binary file not shown.
74 changes: 74 additions & 0 deletions
74
Getting Started/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF/Function.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Amazon.Lambda.Core; | ||
using Syncfusion.XlsIO; | ||
using Syncfusion.XlsIORenderer; | ||
using Syncfusion.Pdf; | ||
using Syncfusion.XlsIO.Implementation; | ||
// 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))] | ||
|
||
namespace Convert_Excel_to_PDF | ||
{ | ||
public class Function | ||
{ | ||
|
||
/// <summary> | ||
/// A simple function that takes a string and does a ToUpper | ||
/// </summary> | ||
/// <param name="input"></param> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
public string FunctionHandler(string input, ILambdaContext context) | ||
{ | ||
using (ExcelEngine excelEngine = new ExcelEngine()) | ||
{ | ||
IApplication application = excelEngine.Excel; | ||
application.DefaultVersion = ExcelVersion.Xlsx; | ||
|
||
//Initializes the SubstituteFont event to perform font substitution during Excel-to-PDF conversion | ||
application.SubstituteFont += new SubstituteFontEventHandler(SubstituteFont); | ||
|
||
FileStream excelStream = new FileStream(@"Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); | ||
IWorkbook workbook = application.Workbooks.Open(excelStream); | ||
|
||
//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; | ||
return Convert.ToBase64String(pdfStream.ToArray()); | ||
} | ||
} | ||
private void SubstituteFont(object sender, SubstituteFontEventArgs args) | ||
{ | ||
string filePath = string.Empty; | ||
FileStream fileStream = null; | ||
|
||
if (args.OriginalFontName == "Calibri") | ||
{ | ||
filePath = Path.GetFullPath(@"Data/calibri.ttf"); | ||
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); | ||
args.AlternateFontStream = fileStream; | ||
} | ||
else if (args.OriginalFontName == "Arial") | ||
{ | ||
filePath = Path.GetFullPath(@"Data/arial.ttf"); | ||
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); | ||
args.AlternateFontStream = fileStream; | ||
} | ||
else | ||
{ | ||
filePath = Path.GetFullPath(@"Data/times.ttf"); | ||
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); | ||
args.AlternateFontStream = fileStream; | ||
} | ||
} | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
...d/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"profiles": { | ||
"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" | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Getting Started/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# AWS Lambda Empty Function Project | ||
|
||
This starter project consists of: | ||
* Function.cs - class file containing a class with a single function handler method | ||
* aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS | ||
|
||
You may also have a test project depending on the options selected. | ||
|
||
The generated function handler is a simple method accepting a string argument that returns the uppercase equivalent of the input string. Replace the body of this method, and parameters, to suit your needs. | ||
|
||
## Here are some steps to follow from Visual Studio: | ||
|
||
To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. | ||
|
||
To view your deployed function open its Function View window by double-clicking the function name shown beneath the AWS Lambda node in the AWS Explorer tree. | ||
|
||
To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. | ||
|
||
To configure event sources for your deployed function, for example to have your function invoked when an object is created in an Amazon S3 bucket, use the Event Sources tab in the opened Function View window. | ||
|
||
To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. | ||
|
||
To view execution logs of invocations of your function use the Logs tab in the opened Function View window. | ||
|
||
## Here are some steps to follow to get started from the command line: | ||
|
||
Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line. | ||
|
||
Install Amazon.Lambda.Tools Global Tools if not already installed. | ||
``` | ||
dotnet tool install -g Amazon.Lambda.Tools | ||
``` | ||
|
||
If already installed check if new version is available. | ||
``` | ||
dotnet tool update -g Amazon.Lambda.Tools | ||
``` | ||
|
||
Execute unit tests | ||
``` | ||
cd "Convert-Excel-to-PDF/test/Convert-Excel-to-PDF.Tests" | ||
dotnet test | ||
``` | ||
|
||
Deploy function to AWS Lambda | ||
``` | ||
cd "Convert-Excel-to-PDF/src/Convert-Excel-to-PDF" | ||
dotnet lambda deploy-function | ||
``` |
16 changes: 16 additions & 0 deletions
16
...d/AWS/AWS Lambda/Convert Excel to PDF/Convert-Excel-to-PDF/aws-lambda-tools-defaults.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Information": [ | ||
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", | ||
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", | ||
"dotnet lambda help", | ||
"All the command line options for the Lambda command can be specified in this file." | ||
], | ||
"profile": "default", | ||
"region": "us-east-1", | ||
"configuration": "Release", | ||
"function-architecture": "x86_64", | ||
"function-runtime": "dotnet6", | ||
"function-memory-size": 256, | ||
"function-timeout": 30, | ||
"function-handler": "Convert-Excel-to-PDF::Convert_Excel_to_PDF.Function::FunctionHandler" | ||
} |
25 changes: 25 additions & 0 deletions
25
Getting Started/AWS/Console Application/Convert Excel to PDF/Convert-Excel-to-PDF.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.7.34202.233 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert-Excel-to-PDF", "Convert-Excel-to-PDF\Convert-Excel-to-PDF.csproj", "{A03293DA-FDB4-457D-BF6E-BA8919F2DC3A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A03293DA-FDB4-457D-BF6E-BA8919F2DC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A03293DA-FDB4-457D-BF6E-BA8919F2DC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A03293DA-FDB4-457D-BF6E-BA8919F2DC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A03293DA-FDB4-457D-BF6E-BA8919F2DC3A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {13B5C523-7292-46EC-A31A-F045224129B9} | ||
EndGlobalSection | ||
EndGlobal |
6 changes: 6 additions & 0 deletions
6
Getting Started/AWS/Console Application/Convert Excel to PDF/Convert-Excel-to-PDF/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
67 changes: 67 additions & 0 deletions
67
...Console Application/Convert Excel to PDF/Convert-Excel-to-PDF/Convert-Excel-to-PDF.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{A03293DA-FDB4-457D-BF6E-BA8919F2DC3A}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>Convert_Excel_to_PDF</RootNamespace> | ||
<AssemblyName>Convert-Excel-to-PDF</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\AWSSDK.Core.3.7.204.8\lib\net45\AWSSDK.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="AWSSDK.Lambda, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\AWSSDK.Lambda.3.7.202.7\lib\net45\AWSSDK.Lambda.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Analyzer Include="..\packages\AWSSDK.Lambda.3.7.202.7\analyzers\dotnet\cs\AWSSDK.Lambda.CodeAnalysis.dll" /> | ||
<Analyzer Include="..\packages\AWSSDK.Lambda.3.7.202.7\analyzers\dotnet\cs\SharedAnalysisCode.dll" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
51 changes: 51 additions & 0 deletions
51
Getting Started/AWS/Console Application/Convert Excel to PDF/Convert-Excel-to-PDF/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Amazon.Lambda.Model; | ||
using Amazon.Lambda; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Amazon; | ||
|
||
namespace Convert_Excel_to_PDF | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Please enter your AWS Access Key ID :"); | ||
string awsAccessKeyID = Console.ReadLine(); | ||
Console.WriteLine("Please enter your AWS Secret Access Key :"); | ||
string awsSecretAccessKey = Console.ReadLine(); | ||
Console.WriteLine("Please enter your Function Name :"); | ||
string functionName = Console.ReadLine(); | ||
//Create a new AmazonLambdaClient | ||
AmazonLambdaClient client = new AmazonLambdaClient(awsAccessKeyID, awsSecretAccessKey, RegionEndpoint.USEast1); | ||
|
||
//Create new InvokeRequest with published function name. | ||
InvokeRequest invoke = new InvokeRequest | ||
{ | ||
FunctionName = functionName, | ||
InvocationType = InvocationType.RequestResponse, | ||
Payload = "\"Test\"" | ||
}; | ||
//Get the InvokeResponse from client InvokeRequest. | ||
InvokeResponse response = client.Invoke(invoke); | ||
|
||
//Read the response stream | ||
var stream = new StreamReader(response.Payload); | ||
JsonReader reader = new JsonTextReader(stream); | ||
var serilizer = new JsonSerializer(); | ||
var responseText = serilizer.Deserialize(reader); | ||
//Convert Base64String into PDF document | ||
byte[] bytes = Convert.FromBase64String(responseText.ToString()); | ||
FileStream fileStream = new FileStream("Sample.xlsx", FileMode.Create); | ||
BinaryWriter writer = new BinaryWriter(fileStream); | ||
writer.Write(bytes, 0, bytes.Length); | ||
writer.Close(); | ||
System.Diagnostics.Process.Start("Sample.xlsx"); | ||
} | ||
} | ||
} |
Oops, something went wrong.