Skip to content

Commit 641b8e4

Browse files
authored
Merge pull request #204 from SyncfusionExamples/264835-CSVToPDFExample
264835-How to convert CSV to PDF in C#,VB.NET?
2 parents 93d5fda + 36a0dd2 commit 641b8e4

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-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.14.36127.28 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert CSV to PDF", "Convert CSV to PDF\Convert CSV to PDF.csproj", "{B689DDBB-3C27-4E5C-A31C-6D5E2995F4E4}"
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+
{B689DDBB-3C27-4E5C-A31C-6D5E2995F4E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B689DDBB-3C27-4E5C-A31C-6D5E2995F4E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B689DDBB-3C27-4E5C-A31C-6D5E2995F4E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B689DDBB-3C27-4E5C-A31C-6D5E2995F4E4}.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 = {270E78FD-B073-44CF-9B9A-06D8ACE3262A}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Convert_CSV_to_PDF</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\*">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Product ID,Product Name,Category,Quantity,Price
2+
1001,Apple,Fruit,10,0.99
3+
1002,Banana,Fruit,20,0.59
4+
1003,Carrot,Vegetable,15,0.49
5+
1004,Tomato,Vegetable,12,0.79
6+
1005,Milk,Dairy,5,1.49
7+
1006,Bread,Bakery,8,2.99
8+
1007,Orange,Fruit,18,0.89

Use Cases/Convert CSV to PDF/.NET/Convert CSV to PDF/Convert CSV to PDF/Output/.gitkeep

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.XlsIO;
3+
using Syncfusion.XlsIORenderer;
4+
5+
namespace Convert_CSV_to_PDF
6+
{
7+
class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
using (ExcelEngine excelEngine = new ExcelEngine())
12+
{
13+
IApplication application = excelEngine.Excel;
14+
application.DefaultVersion = ExcelVersion.Xlsx;
15+
FileStream inputStream = new FileStream("Data/Sample.csv", FileMode.Open, FileAccess.Read);
16+
IWorkbook workbook = application.Workbooks.Open(inputStream);
17+
IWorksheet sheet = workbook.Worksheets[0];
18+
19+
//Auto-fit all columns in the used range to prevent cropping
20+
sheet.UsedRange.AutofitColumns();
21+
22+
//Initialize XlsIO renderer
23+
XlsIORenderer renderer = new XlsIORenderer();
24+
25+
//Convert CSV document into PDF document
26+
PdfDocument pdfDocument = renderer.ConvertToPDF(sheet);
27+
28+
//Saving the PDF document
29+
FileStream outputStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
30+
pdfDocument.Save(outputStream);
31+
32+
//Dispose streams
33+
inputStream.Dispose();
34+
outputStream.Dispose();
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)