From cbe1cb22d9510360627851f8b40200ece8fad2d0 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 2 Apr 2025 13:04:28 +0530 Subject: [PATCH] 951026 Creating a Linear Gradient Brush with Multiple Colors in a PDF Document --- ...ar-Gradient-Brush-with-Multiple-Colors.sln | 22 ++++++++ ...Gradient-Brush-with-Multiple-Colors.csproj | 15 ++++++ .../Output/gitkeep.txt | 0 .../Program.cs | 51 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors.sln create mode 100644 Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Linear-Gradient-Brush-with-Multiple-Colors.csproj create mode 100644 Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Output/gitkeep.txt create mode 100644 Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs diff --git a/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors.sln b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors.sln new file mode 100644 index 00000000..b1e33090 --- /dev/null +++ b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors.sln @@ -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 diff --git a/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Linear-Gradient-Brush-with-Multiple-Colors.csproj b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Linear-Gradient-Brush-with-Multiple-Colors.csproj new file mode 100644 index 00000000..2fca0542 --- /dev/null +++ b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Linear-Gradient-Brush-with-Multiple-Colors.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Linear_Gradient_Brush_with_Multiple_Colors + enable + enable + + + + + + + diff --git a/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Output/gitkeep.txt b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs new file mode 100644 index 00000000..d2a0e858 --- /dev/null +++ b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs @@ -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); + } +} \ No newline at end of file