Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
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.14.36221.1 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Copy_fonts_to_linux_containers", "Copy_fonts_to_linux_containers\Copy_fonts_to_linux_containers.csproj", "{99A9E4D7-F051-40E7-AD6B-299EA8596F68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{99A9E4D7-F051-40E7-AD6B-299EA8596F68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99A9E4D7-F051-40E7-AD6B-299EA8596F68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99A9E4D7-F051-40E7-AD6B-299EA8596F68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99A9E4D7-F051-40E7-AD6B-299EA8596F68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6F934CE-C083-4CAF-A048-13ACF61362E4}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.116.1" />
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<Folder Include="Output\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>Container (Dockerfile)</ActiveDebugProfile>
</PropertyGroup>
</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Base runtime image (root user by default)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base

RUN apt-get update -y && apt-get install fontconfig -y

WORKDIR /app

# Copy fonts from your project folder into the container
COPY ["Copy_fonts_to_linux_containers/Fonts/", "/usr/local/share/fonts/"]

# ------------------ build stage ------------------
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

COPY ["Copy_fonts_to_linux_containers/Copy_fonts_to_linux_containers.csproj", "Copy_fonts_to_linux_containers/"]
RUN dotnet restore "./Copy_fonts_to_linux_containers/Copy_fonts_to_linux_containers.csproj"

COPY . .
WORKDIR "/src/Copy_fonts_to_linux_containers"
RUN dotnet build "./Copy_fonts_to_linux_containers.csproj" -c $BUILD_CONFIGURATION -o /app/build

# ------------------ publish stage ------------------
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Copy_fonts_to_linux_containers.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# ------------------ final stage ------------------
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Copy_fonts_to_linux_containers.dll"]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Syncfusion.Pdf;
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer;
using System.IO;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Copy_fonts_to_linux_containers
{
class Program
{
static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

//Load existing Excel file
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);

//Convert to PDF
XlsIORenderer renderer = new XlsIORenderer();
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);

//Create the MemoryStream to save the converted PDF.
MemoryStream pdfStream = new MemoryStream();

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Sample.pdf"), FileMode.Create, FileAccess.Write);
pdfDocument.Save(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Copy_fonts_to_linux_containers": {
"commandName": "Project"
},
"Container (Dockerfile)": {
"commandName": "Docker"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copy necessary fonts to Linux containers
----------------------------------------

XlsIO's Excel-to-PDF conversion on Linux uses the system fonts available inside the container. By default, only a few fonts are installed. Copy the required fonts to "/usr/local/share/fonts/" before conversion.

How to run this example
-----------------------

* Download this project to your local disk.
* Create a Fonts folder inside the project (or next to the solution).
* Copy the required font files (.ttf/.otf) into the Fonts folder.
* Open the solution in Visual Studio.
* Rebuild the solution to restore/install NuGet packages.
* Run the application.