Skip to content

Commit fdde00f

Browse files
892878: Update the sample.
1 parent 6d7a4fe commit fdde00f

File tree

6 files changed

+37
-96
lines changed

6 files changed

+37
-96
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.11.35222.181
4+
VisualStudioVersion = 17.11.35219.272
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTML-to-PDF-AzureApp-container", "HTML-to-PDF-AzureApp-container\HTML-to-PDF-AzureApp-container.csproj", "{08CEB4C5-BEDA-4D5A-9E3D-1E2F62496BB2}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTML-to-PDF-AzureApp-container", "HTML-to-PDF-AzureApp-container\HTML-to-PDF-AzureApp-container.csproj", "{599D73EC-B17D-485B-A46D-C3DB6A37A859}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{08CEB4C5-BEDA-4D5A-9E3D-1E2F62496BB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{08CEB4C5-BEDA-4D5A-9E3D-1E2F62496BB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{08CEB4C5-BEDA-4D5A-9E3D-1E2F62496BB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{08CEB4C5-BEDA-4D5A-9E3D-1E2F62496BB2}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{599D73EC-B17D-485B-A46D-C3DB6A37A859}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{599D73EC-B17D-485B-A46D-C3DB6A37A859}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{599D73EC-B17D-485B-A46D-C3DB6A37A859}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{599D73EC-B17D-485B-A46D-C3DB6A37A859}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
2222
GlobalSection(ExtensibilityGlobals) = postSolution
23-
SolutionGuid = {88AC76D3-AFCA-423A-9B14-ECA7A527F702}
23+
SolutionGuid = {83D1C6B4-750C-45AD-B261-C92A6EED1A8C}
2424
EndGlobalSection
2525
EndGlobal

Azure/HTML-to-PDF-AzureApp-container/HTML-to-PDF-AzureApp-container/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
22

33
# This stage is used when running from VS in fast mode (Default for Debug configuration)
4-
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base
4+
FROM mcr.microsoft.com/azure-functions/dotnet:4-dotnet8.0 AS base
55
WORKDIR /home/site/wwwroot
66
EXPOSE 8080
77

Azure/HTML-to-PDF-AzureApp-container/HTML-to-PDF-AzureApp-container/Function1.cs

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
using Microsoft.AspNetCore.Http;
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
24
using Microsoft.AspNetCore.Mvc;
3-
using Microsoft.Azure.Functions.Worker;
5+
using Microsoft.Azure.WebJobs;
6+
using Microsoft.Azure.WebJobs.Extensions.Http;
7+
using Microsoft.AspNetCore.Http;
48
using Microsoft.Extensions.Logging;
9+
using Newtonsoft.Json;
10+
using Microsoft.Azure.Functions.Worker;
511
using Syncfusion.HtmlConverter;
6-
using Syncfusion.Pdf;
712
using Syncfusion.Pdf.Graphics;
13+
using Syncfusion.Pdf;
814
using System.Runtime.InteropServices;
915

1016
namespace HTML_to_PDF_AzureApp_container
@@ -20,109 +26,56 @@ public Function1(ILogger<Function1> logger)
2026

2127
[Function("Function1")]
2228
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
23-
2429
{
25-
2630
string blinkBinariesPath = string.Empty;
27-
2831
MemoryStream ms = null;
2932

3033
try
31-
3234
{
35+
// Attempt to initialize Blink binaries
36+
blinkBinariesPath = SetupBlinkBinaries();
3337

34-
try
35-
36-
{
37-
38-
blinkBinariesPath = SetupBlinkBinaries();
39-
40-
}
41-
42-
catch
43-
44-
{
45-
46-
throw new Exception("BlinkBinaries initialization failed");
47-
48-
}
49-
50-
//Initialize the HTML to PDF converter with the Blink rendering engine.
51-
38+
// Initialize the HTML to PDF converter with the Blink rendering engine.
5239
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
53-
5440
BlinkConverterSettings settings = new BlinkConverterSettings();
5541

56-
//Set command line arguments to run without sandbox.
57-
42+
// Set command line arguments to run without sandbox.
5843
settings.CommandLineArguments.Add("--no-sandbox");
59-
6044
settings.CommandLineArguments.Add("--disable-setuid-sandbox");
61-
6245
settings.BlinkPath = blinkBinariesPath;
6346

64-
//Assign BlinkConverter settings to the HTML converter
65-
47+
// Assign BlinkConverter settings to the HTML converter
6648
htmlConverter.ConverterSettings = settings;
6749

68-
//Convert URL to PDF
69-
50+
// Convert URL to PDF
7051
PdfDocument document = htmlConverter.Convert("https://www.google.com/");
71-
7252
ms = new MemoryStream();
7353

74-
//Save and close the PDF document
75-
54+
// Save and close the PDF document
7655
document.Save(ms);
77-
7856
document.Close();
79-
8057
}
81-
8258
catch (Exception ex)
83-
8459
{
85-
86-
//Create a new PDF document.
87-
60+
// Handle any exception by creating an error PDF document
8861
PdfDocument document = new PdfDocument();
89-
90-
//Add a page to the document.
91-
9262
PdfPage page = document.Pages.Add();
93-
94-
//Create PDF graphics for the page.
95-
9663
PdfGraphics graphics = page.Graphics;
97-
98-
//Set the standard font.
99-
10064
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
10165

102-
//Draw the text.
103-
66+
// Draw the exception message in the PDF
10467
graphics.DrawString(ex.Message, font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
10568

106-
//Creating the stream object.
107-
10869
ms = new MemoryStream();
109-
110-
//Save the document into memory stream.
111-
11270
document.Save(ms);
113-
114-
//Close the document.
115-
11671
document.Close(true);
117-
11872
}
11973

12074
ms.Position = 0;
121-
12275
return new FileStreamResult(ms, "application/pdf");
123-
12476
}
12577

78+
12679
private static string SetupBlinkBinaries()
12780

12881
{
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
5-
<OutputType>Exe</OutputType>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
85
<RootNamespace>HTML_to_PDF_AzureApp_container</RootNamespace>
96
<DockerFastModeProjectMountDirectory>/home/site/wwwroot</DockerFastModeProjectMountDirectory>
107
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
118
</PropertyGroup>
129
<ItemGroup>
13-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
14-
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
15-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
16-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
17-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" />
18-
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
19-
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
10+
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
11+
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
2012
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
2113
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Linux" Version="26.2.11" />
2214
</ItemGroup>
@@ -29,7 +21,4 @@
2921
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
3022
</None>
3123
</ItemGroup>
32-
<ItemGroup>
33-
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
34-
</ItemGroup>
35-
</Project>
24+
</Project>

Azure/HTML-to-PDF-AzureApp-container/HTML-to-PDF-AzureApp-container/Properties/launchSettings.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
"profiles": {
33
"HTML_to_PDF_AzureApp_container": {
44
"commandName": "Project",
5-
"commandLineArgs": "--port 7213"
5+
"commandLineArgs": "--port 7021"
66
},
77
"Container (Dockerfile)": {
88
"commandName": "Docker",
99
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
10-
"DockerfileRunArguments": "--init",
11-
"httpPort": 31335,
10+
"httpPort": 31902,
1211
"useSSL": false
1312
}
1413
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"dependencies": {
3-
"appInsights1": {
4-
"type": "appInsights",
5-
"connectionId": "APPLICATIONINSIGHTS_CONNECTION_STRING"
6-
},
73
"storage1": {
84
"type": "storage",
95
"connectionId": "AzureWebJobsStorage"
6+
},
7+
"appInsights1": {
8+
"type": "appInsights",
9+
"connectionId": "APPLICATIONINSIGHTS_CONNECTION_STRING"
1010
}
1111
}
1212
}

0 commit comments

Comments
 (0)