Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f6cf9e

Browse files
authoredApr 21, 2025··
Merge pull request #157 from SyncfusionExamples/953749
953749 Added sample code for apply style in PDF grid cell.
2 parents 95244f6 + ab4302d commit 1f6cf9e

File tree

4 files changed

+85
-0
lines changed

4 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.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applying-Customizing-Styles-in-PDF-Grid", "Applying-Customizing-Styles-in-PDF-Grid\Applying-Customizing-Styles-in-PDF-Grid.csproj", "{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}"
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+
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Applying_Customizing_Styles_in_PDF_Grid</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

‎Table/PdfGrid/Applying-Customizing-Styles-in-PDF-Grid/.NET/Applying-Customizing-Styles-in-PDF-Grid/Output/gitkeep.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Syncfusion.Pdf.Graphics;
2+
using Syncfusion.Pdf.Grid;
3+
using Syncfusion.Pdf;
4+
using System.Data;
5+
using Syncfusion.Drawing;
6+
7+
//Create a new PDF document.
8+
PdfDocument document = new PdfDocument();
9+
//Add a page.
10+
PdfPage page = document.Pages.Add();
11+
//Create a PdfGrid.
12+
PdfGrid pdfGrid = new PdfGrid();
13+
//Create a DataTable.
14+
DataTable dataTable = new DataTable();
15+
//Add columns to the DataTable
16+
dataTable.Columns.Add("ID");
17+
dataTable.Columns.Add("Name");
18+
//Add rows to the DataTable.
19+
dataTable.Rows.Add(new object[] { "E01", "Clay" });
20+
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
21+
//Assign data source.
22+
pdfGrid.DataSource = dataTable;
23+
24+
//Create Cell Style
25+
PdfGridCellStyle headerStyle = new PdfGridCellStyle();
26+
headerStyle.TextBrush = PdfBrushes.Red;
27+
headerStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.LightBlue);
28+
//Apply style to the header row
29+
pdfGrid.Headers[0].ApplyStyle(headerStyle);
30+
31+
//Create Cell Style
32+
PdfGridCellStyle rowStyle = new PdfGridCellStyle();
33+
rowStyle.TextBrush = PdfBrushes.Cyan;
34+
rowStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.YellowGreen);
35+
//Apply style to the first row
36+
pdfGrid.Rows[0].ApplyStyle(rowStyle);
37+
38+
//Draw grid to the page of PDF document.
39+
pdfGrid.Draw(page, new PointF(10, 10));
40+
41+
//Create file stream.
42+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
43+
{
44+
//Save the PDF document to file stream.
45+
document.Save(outputFileStream);
46+
}
47+
//Close the document
48+
document.Close(true);

0 commit comments

Comments
 (0)
Please sign in to comment.