Skip to content

Commit ce52f36

Browse files
Merge pull request #342 from SyncfusionExamples/ES-943656-Add-sample-GCR
ES-943656 - Add sample to deploy docker web sample in Google Cloud Run
2 parents 1037c39 + fbed6b6 commit ce52f36

File tree

96 files changed

+74794
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+74794
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32901.215
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert-Word-Document-to-PDF", "Convert-Word-Document-to-PDF\Convert-Word-Document-to-PDF.csproj", "{9C945DA3-23EB-47E1-9061-B64B9BE02B41}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9C945DA3-23EB-47E1-9061-B64B9BE02B41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9C945DA3-23EB-47E1-9061-B64B9BE02B41}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9C945DA3-23EB-47E1-9061-B64B9BE02B41}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9C945DA3-23EB-47E1-9061-B64B9BE02B41}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E88E64CC-7DB7-4280-A0E3-4531A7826E92}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using Convert_Word_Document_to_PDF.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using Syncfusion.DocIO.DLS;
6+
using Syncfusion.DocIO;
7+
using Syncfusion.DocIORenderer;
8+
using Syncfusion.Pdf;
9+
using Syncfusion.Drawing;
10+
using SkiaSharp;
11+
12+
namespace Convert_Word_Document_to_PDF.Controllers
13+
{
14+
public class HomeController : Controller
15+
{
16+
private readonly ILogger<HomeController> _logger;
17+
18+
public HomeController(ILogger<HomeController> logger)
19+
{
20+
_logger = logger;
21+
}
22+
23+
public IActionResult Index()
24+
{
25+
return View();
26+
}
27+
28+
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
29+
{
30+
//Sets the alternate font when a specified font is not installed in the production environment
31+
if (args.OriginalFontName == "Times New Roman")
32+
args.AlternateFontStream = new FileStream(Path.GetFullPath("Fonts/arial-unicode-ms.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
33+
else
34+
args.AlternateFontStream = new FileStream(Path.GetFullPath("Fonts/arial-unicode-ms.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
35+
}
36+
public ActionResult ConvertWordtoPDF()
37+
{
38+
//Open the file as Stream
39+
using (FileStream docStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.Read))
40+
{
41+
//Loads file stream into Word document
42+
using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Automatic))
43+
{
44+
45+
//Hooks the font substitution event
46+
wordDocument.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
47+
48+
//Instantiation of DocIORenderer for Word to PDF conversion
49+
using (DocIORenderer render = new DocIORenderer())
50+
{
51+
//Converts Word document into PDF document
52+
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
53+
54+
//Unhooks the font substitution event after converting to PDF
55+
wordDocument.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
56+
57+
//Saves the PDF document to MemoryStream.
58+
MemoryStream stream = new MemoryStream();
59+
pdfDocument.Save(stream);
60+
stream.Position = 0;
61+
62+
//Download PDF document in the browser.
63+
return File(stream, "application/pdf", "Sample.pdf");
64+
}
65+
}
66+
}
67+
}
68+
public IActionResult Privacy()
69+
{
70+
return View();
71+
}
72+
73+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
74+
public IActionResult Error()
75+
{
76+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
77+
}
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>Convert_Word_Document_to_PDF</RootNamespace>
8+
<UserSecretsId>59f40553-d8a7-4391-b53e-6ea79848e31a</UserSecretsId>
9+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.116.1" />
14+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="28.2.6" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<Compile Update="Controllers\HomeController.cs">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</Compile>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<None Update="Data\Template.docx">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
<None Update="Fonts\arial-unicode-ms.ttf">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</None>
30+
<None Update="Fonts\times.ttf">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
</ItemGroup>
34+
35+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>Container (Dockerfile)</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 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.
2+
3+
# This stage is used when running from VS in fast mode (Default for Debug configuration)
4+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
5+
# Install required font packages
6+
RUN apt-get update -y && apt-get install -y \
7+
fontconfig \
8+
libfontconfig1 \
9+
libfreetype6 \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
USER $APP_UID
13+
14+
WORKDIR /app
15+
16+
COPY ["Fonts/*.*", "/usr/local/share/fonts/"]
17+
# This stage is used to build the service project
18+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
19+
ARG BUILD_CONFIGURATION=Release
20+
WORKDIR /src
21+
COPY ["Convert-Word-Document-to-PDF.csproj", "."]
22+
RUN dotnet restore "./Convert-Word-Document-to-PDF.csproj"
23+
COPY . .
24+
WORKDIR "/src/."
25+
RUN dotnet build "./Convert-Word-Document-to-PDF.csproj" -c $BUILD_CONFIGURATION -o /app/build
26+
27+
# This stage is used to publish the service project to be copied to the final stage
28+
FROM build AS publish
29+
ARG BUILD_CONFIGURATION=Release
30+
RUN dotnet publish "./Convert-Word-Document-to-PDF.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
31+
32+
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
33+
FROM base AS final
34+
WORKDIR /app
35+
COPY --from=publish /app/publish .
36+
ENTRYPOINT ["dotnet", "Convert-Word-Document-to-PDF.dll"]
Loading
Loading

0 commit comments

Comments
 (0)