Skip to content

Commit 5ca938f

Browse files
authored
Merge pull request #180 from SyncfusionExamples/842226-ExcelToPdfLinuxExample
842226-Prepare UG to convert Excel file to PDF in Linux using XlsIO
2 parents 6f667b7 + cb2ecaa commit 5ca938f

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert Excel to PDF", "Convert Excel to PDF\Convert Excel to PDF.csproj", "{508E0748-8D9A-41E5-9F44-6C43714D8ED3}"
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+
{508E0748-8D9A-41E5-9F44-6C43714D8ED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{508E0748-8D9A-41E5-9F44-6C43714D8ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{508E0748-8D9A-41E5-9F44-6C43714D8ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{508E0748-8D9A-41E5-9F44-6C43714D8ED3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Convert_Excel_to_PDF</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="*" />
13+
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="*" />
14+
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<None Update="Output\*">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>

Getting Started/Linux/Convert Excel to PDF/Convert Excel to PDF/Output/.gitkeep

Whitespace-only changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Syncfusion.XlsIO;
2+
using Syncfusion.XlsIORenderer;
3+
using Syncfusion.Pdf;
4+
5+
namespace Excel_to_PDF_Linux
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
using (ExcelEngine excelEngine = new ExcelEngine())
12+
{
13+
IApplication application = excelEngine.Excel;
14+
application.DefaultVersion = ExcelVersion.Xlsx;
15+
16+
//Load existing Excel file
17+
FileStream inputStream = new FileStream("Data/Sample.xlsx", FileMode.Open, FileAccess.Read);
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
20+
//Convert to PDF
21+
XlsIORenderer renderer = new XlsIORenderer();
22+
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
23+
24+
//Create the MemoryStream to save the converted PDF.
25+
MemoryStream pdfStream = new MemoryStream();
26+
27+
#region Save
28+
//Saving the workbook
29+
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write);
30+
pdfDocument.Save(outputStream);
31+
#endregion
32+
33+
//Dispose streams
34+
outputStream.Dispose();
35+
inputStream.Dispose();
36+
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)