Skip to content

953749 Added sample code for apply style in PDF grid cell. #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
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,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AAB6E11-34D4-4D9D-9FDD-27224271B1E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Applying_Customizing_Styles_in_PDF_Grid</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Grid;
using Syncfusion.Pdf;
using System.Data;
using Syncfusion.Drawing;

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page.
PdfPage page = document.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;

//Create Cell Style
PdfGridCellStyle headerStyle = new PdfGridCellStyle();
headerStyle.TextBrush = PdfBrushes.Red;
headerStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.LightBlue);
//Apply style to the header row
pdfGrid.Headers[0].ApplyStyle(headerStyle);

//Create Cell Style
PdfGridCellStyle rowStyle = new PdfGridCellStyle();
rowStyle.TextBrush = PdfBrushes.Cyan;
rowStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.YellowGreen);
//Apply style to the first row
pdfGrid.Rows[0].ApplyStyle(rowStyle);

//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
}
//Close the document
document.Close(true);
Loading