diff --git a/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF.sln b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF.sln new file mode 100644 index 00000000..440ce5e7 --- /dev/null +++ b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF.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}") = "Radial-gradient-rectangle-in-PDF", "Radial-gradient-rectangle-in-PDF\Radial-gradient-rectangle-in-PDF.csproj", "{D570FDA5-9A74-4EF2-879A-BC4DEE988669}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D570FDA5-9A74-4EF2-879A-BC4DEE988669}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D570FDA5-9A74-4EF2-879A-BC4DEE988669}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D570FDA5-9A74-4EF2-879A-BC4DEE988669}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D570FDA5-9A74-4EF2-879A-BC4DEE988669}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Output/gitkeep.txt b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs new file mode 100644 index 00000000..f3ce8c22 --- /dev/null +++ b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs @@ -0,0 +1,63 @@ +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + +// Create a new PDF document. +PdfDocument document = new PdfDocument(); + +// Add a page to the document. +PdfPage page = document.Pages.Add(); + +// Create PDF graphics object for the page. +PdfGraphics graphics = page.Graphics; + +// Define rectangle dimensions. +float rectWidth = 150f; +float rectHeight = 150f; + +// Calculate position to center the rectangle horizontally at the top. +float pageWidth = page.GetClientSize().Width; +float startX = (pageWidth - rectWidth) / 2; +float startY = 60f; // Positioned near the top + +// Define the rectangle path. +PdfPath path = new PdfPath(); +path.AddRectangle(new RectangleF(startX, startY, rectWidth, rectHeight)); + +// Define a smooth gradient color scheme. +List gradientColors = new List + { + Color.CornflowerBlue, + Color.MediumPurple, + Color.DeepPink + }; + +List gradientPositions = new List { 0.0f, 0.5f, 1.0f }; + +PdfColorBlend colorBlend = new PdfColorBlend +{ + Colors = gradientColors.ToArray(), + Positions = gradientPositions.ToArray() +}; + +// Calculate the radius for the radial gradient. +float radius = (float)Math.Sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)) / 2; + +// Create a radial gradient brush centered in the rectangle. +PointF center = new PointF(startX + rectWidth / 2, startY + rectHeight / 2); +PdfRadialGradientBrush radialBrush = new PdfRadialGradientBrush(center, 0, center, radius, gradientColors[0], gradientColors[gradientColors.Count - 1]) +{ + InterpolationColors = colorBlend +}; + +// Draw the rectangle with the radial gradient fill. +graphics.DrawPath(radialBrush, path); + +// Save the document to file. +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +{ + document.Save(fileStream); +} + +// Close the document. +document.Close(true); \ No newline at end of file diff --git a/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Radial-gradient-rectangle-in-PDF.csproj b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Radial-gradient-rectangle-in-PDF.csproj new file mode 100644 index 00000000..5dbb4302 --- /dev/null +++ b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Radial-gradient-rectangle-in-PDF.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Radial_gradient_rectangle_in_PDF + enable + enable + + + + + + +