Skip to content

Commit 45e77af

Browse files
Merge pull request #154 from SyncfusionExamples/951026
951026 Creating a Linear Gradient Brush with Multiple Colors in a PDF document
2 parents f4dc5bf + cbe1cb2 commit 45e77af

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
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}") = "Linear-Gradient-Brush-with-Multiple-Colors", "Linear-Gradient-Brush-with-Multiple-Colors\Linear-Gradient-Brush-with-Multiple-Colors.csproj", "{4466A1C9-0D8C-4290-A2C3-C0910699BE92}"
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+
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.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>Linear_Gradient_Brush_with_Multiple_Colors</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>

Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Output/gitkeep.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+

2+
using Syncfusion.Pdf.Graphics;
3+
using Syncfusion.Pdf;
4+
using Syncfusion.Drawing;
5+
using System.Reflection.Metadata;
6+
7+
// Create a new PDF document
8+
using (PdfDocument document = new PdfDocument())
9+
{
10+
// Add a page to the document
11+
PdfPage page = document.Pages.Add();
12+
13+
// Create PDF graphics for the page
14+
PdfGraphics graphics = page.Graphics;
15+
16+
// Create a new PDF linear gradient brush
17+
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(
18+
new RectangleF(new PointF(0, 0), new SizeF(200, 100)),
19+
Color.Red, Color.Blue,
20+
PdfLinearGradientMode.Horizontal
21+
);
22+
23+
// Create and configure the color blend
24+
PdfColorBlend colorBlend = new PdfColorBlend(4)
25+
{
26+
// Define the colors for the gradient
27+
Colors = new PdfColor[]
28+
{
29+
Color.Red,
30+
Color.Yellow,
31+
Color.Green,
32+
Color.Blue
33+
},
34+
35+
// Define the position of each color in the gradient
36+
Positions = new float[] { 0, 0.3f, 0.7f, 1 }
37+
};
38+
39+
// Apply the color blend to the linear gradient brush
40+
brush.InterpolationColors = colorBlend;
41+
42+
// Draw a rectangle filled with the gradient
43+
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));
44+
45+
//Create file stream.
46+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
47+
{
48+
//Save the PDF document to file stream.
49+
document.Save(outputFileStream);
50+
}
51+
}

0 commit comments

Comments
 (0)