diff --git a/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln new file mode 100644 index 00000000..19031782 --- /dev/null +++ b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-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}") = "Multi-color-radial-gradient-fill-in-PDF", "Multi-color-radial-gradient-fill-in-PDF\Multi-color-radial-gradient-fill-in-PDF.csproj", "{6A8258DB-87FA-4361-B464-70774FD0E6AE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6A8258DB-87FA-4361-B464-70774FD0E6AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A8258DB-87FA-4361-B464-70774FD0E6AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A8258DB-87FA-4361-B464-70774FD0E6AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A8258DB-87FA-4361-B464-70774FD0E6AE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Multi-color-radial-gradient-fill-in-PDF.csproj b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Multi-color-radial-gradient-fill-in-PDF.csproj new file mode 100644 index 00000000..5f5f7907 --- /dev/null +++ b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Multi-color-radial-gradient-fill-in-PDF.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Multi-color-radial-gradient-fill-in-PDF + enable + enable + + + + + + + diff --git a/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Output/gitkeep.txt b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs new file mode 100644 index 00000000..52729580 --- /dev/null +++ b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs @@ -0,0 +1,70 @@ +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(); + +// Get graphics context of the added page. +PdfGraphics graphics = page.Graphics; + +// Define the rectangle dimensions. +float rectWidth = 416; +float rectHeight = 145; + +// Calculate the top-center position. +float pageWidth = page.GetClientSize().Width; +float rectX = (pageWidth - rectWidth) / 2; // Centered horizontally +float rectY = 50; // Distance from the top + +// Define the rectangle path. +PdfPath path = new PdfPath(); +path.AddRectangle(new RectangleF(rectX, rectY, rectWidth, rectHeight)); + +// Define gradient colors using RGB (byte values from 0 to 255). +List finalGradientColors = new List +{ + new PdfColor(0, 63, 255), // Blue + new PdfColor(0, 200, 83), // Green + new PdfColor(255, 193, 7), // Amber + new PdfColor(255, 0, 139) // Magenta +}; + +// Define positions for the gradient colors. +List finalGradientPositions = new List { 0, 0.2f, 0.8f, 1 }; + +// Create a color blend object for the gradient. +PdfColorBlend gradientColorBlend = new PdfColorBlend +{ + Colors = finalGradientColors.ToArray(), + Positions = finalGradientPositions.ToArray() +}; + +// Calculate the center point and radius for the radial gradient. +PointF center = new PointF(rectX + rectWidth / 2, rectY + rectHeight / 2); +float radius = (float)Math.Sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)) / 2; + +// Create and configure the radial gradient brush. +PdfRadialGradientBrush rectangleGradientBrush = new PdfRadialGradientBrush( + center, 0, center, radius, + finalGradientColors[0], + finalGradientColors[finalGradientColors.Count - 1] +) +{ + InterpolationColors = gradientColorBlend +}; + +// Draw the gradient-filled rectangle. +graphics.DrawPath(rectangleGradientBrush, path); + +//Create file stream. +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +{ + document.Save(outputFileStream); +} + +// Close the document and release resources. +document.Close(true);