Skip to content

951026 Creating a Linear Gradient Brush with Multiple Colors in a PDF document #154

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 8, 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}") = "Linear-Gradient-Brush-with-Multiple-Colors", "Linear-Gradient-Brush-with-Multiple-Colors\Linear-Gradient-Brush-with-Multiple-Colors.csproj", "{4466A1C9-0D8C-4290-A2C3-C0910699BE92}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4466A1C9-0D8C-4290-A2C3-C0910699BE92}.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>Linear_Gradient_Brush_with_Multiple_Colors</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,51 @@

using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf;
using Syncfusion.Drawing;
using System.Reflection.Metadata;

// Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
// Add a page to the document
PdfPage page = document.Pages.Add();

// Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;

// Create a new PDF linear gradient brush
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(
new RectangleF(new PointF(0, 0), new SizeF(200, 100)),
Color.Red, Color.Blue,
PdfLinearGradientMode.Horizontal
);

// Create and configure the color blend
PdfColorBlend colorBlend = new PdfColorBlend(4)
{
// Define the colors for the gradient
Colors = new PdfColor[]
{
Color.Red,
Color.Yellow,
Color.Green,
Color.Blue
},

// Define the position of each color in the gradient
Positions = new float[] { 0, 0.3f, 0.7f, 1 }
};

// Apply the color blend to the linear gradient brush
brush.InterpolationColors = colorBlend;

// Draw a rectangle filled with the gradient
graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100));

//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);
}
}
Loading