From babc005c277a907d494f326207ad29ed9fbe0522 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Mon, 2 Jun 2025 13:01:46 +0530 Subject: [PATCH 1/4] 957011 Added sample code for apply Radial Gradient fill to shapes in a PDF document --- .../Apply-Radial-Gradient-fill-to-shapes.sln | 22 ++++++ ...pply-Radial-Gradient-fill-to-shapes.csproj | 15 ++++ .../Output/gitkeep.txt | 0 .../Program.cs | 70 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln create mode 100644 Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.csproj create mode 100644 Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Output/gitkeep.txt create mode 100644 Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Program.cs diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln new file mode 100644 index 00000000..f928a52c --- /dev/null +++ b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.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}") = "Apply-Radial-Gradient-fill-to-shapes", "Apply-Radial-Gradient-fill-to-shapes\Apply-Radial-Gradient-fill-to-shapes.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/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.csproj b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.csproj new file mode 100644 index 00000000..e87ab30e --- /dev/null +++ b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Apply_Radial_Gradient_fill_to_shapes + enable + enable + + + + + + + diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Output/gitkeep.txt b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Program.cs b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Program.cs new file mode 100644 index 00000000..7d07770d --- /dev/null +++ b/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/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. +List finalGradientColors = new List + { + new PdfColor(0, 0.247058809f, 1, 0), + new PdfColor(0, 0.247058809f, 1, 0), + new PdfColor(1, 0, 0.545454562f, 80), + new PdfColor(1, 0, 0.545454562f, 80) + }; + +// 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); + +// Save the PDF document to a file using a file stream. +using (FileStream fs = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) +{ + document.Save(fs); +} + +// Close the document and release resources. +document.Close(true); From 1727e5e3b8397f2617c0001cb60c99aca3a65129 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Mon, 2 Jun 2025 17:58:05 +0530 Subject: [PATCH 2/4] 957011 Resolved the given feedback. --- .../.NET/Multi-color-radial-gradient-fill-in-PDF.sln} | 2 +- .../Multi-color-radial-gradient-fill-in-PDF.csproj} | 2 +- .../Multi-color-radial-gradient-fill-in-PDF}/Output/gitkeep.txt | 0 .../.NET/Multi-color-radial-gradient-fill-in-PDF}/Program.cs | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename Shapes/{Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln => Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln} (79%) rename Shapes/{Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.csproj => Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Multi-color-radial-gradient-fill-in-PDF.csproj} (82%) rename Shapes/{Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes => Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF}/Output/gitkeep.txt (100%) rename Shapes/{Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes => Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF}/Program.cs (100%) diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln similarity index 79% rename from Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln rename to Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln index f928a52c..19031782 100644 --- a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes.sln +++ b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln @@ -3,7 +3,7 @@ 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}") = "Apply-Radial-Gradient-fill-to-shapes", "Apply-Radial-Gradient-fill-to-shapes\Apply-Radial-Gradient-fill-to-shapes.csproj", "{6A8258DB-87FA-4361-B464-70774FD0E6AE}" +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 diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.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 similarity index 82% rename from Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.csproj rename to Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Multi-color-radial-gradient-fill-in-PDF.csproj index e87ab30e..5f5f7907 100644 --- a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Apply-Radial-Gradient-fill-to-shapes.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 @@ -3,7 +3,7 @@ Exe net8.0 - Apply_Radial_Gradient_fill_to_shapes + Multi-color-radial-gradient-fill-in-PDF enable enable diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Output/gitkeep.txt b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Output/gitkeep.txt similarity index 100% rename from Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Output/gitkeep.txt rename to Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Output/gitkeep.txt diff --git a/Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Program.cs b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs similarity index 100% rename from Shapes/Apply-Radial-Gradient-fill-to-shapes/.NET/Apply-Radial-Gradient-fill-to-shapes/Program.cs rename to Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs From feffe76adf5b550c1e9fbc7655a8a506c8c4b126 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 4 Jun 2025 15:06:07 +0530 Subject: [PATCH 3/4] 957011 Resolved the given feedback. --- .../Program.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 index 7d07770d..bd69022a 100644 --- 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 @@ -2,7 +2,7 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -// Create a new PDF document. +// Create a new PDF document. PdfDocument document = new PdfDocument(); // Add a page to the document. @@ -24,14 +24,14 @@ PdfPath path = new PdfPath(); path.AddRectangle(new RectangleF(rectX, rectY, rectWidth, rectHeight)); -// Define gradient colors. +// Define gradient colors using RGB (byte values from 0 to 255). List finalGradientColors = new List - { - new PdfColor(0, 0.247058809f, 1, 0), - new PdfColor(0, 0.247058809f, 1, 0), - new PdfColor(1, 0, 0.545454562f, 80), - new PdfColor(1, 0, 0.545454562f, 80) - }; +{ + new PdfColor(0, 63, 255), // Blue-ish + new PdfColor(0, 63, 255), // Same blue + new PdfColor(255, 0, 139), // Reddish-purple + new PdfColor(255, 0, 139) // Same reddish-purple +}; // Define positions for the gradient colors. List finalGradientPositions = new List { 0, 0.2f, 0.8f, 1 }; @@ -60,10 +60,10 @@ // Draw the gradient-filled rectangle. graphics.DrawPath(rectangleGradientBrush, path); -// Save the PDF document to a file using a file stream. -using (FileStream fs = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) +//Create file stream. +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) { - document.Save(fs); + document.Save(outputFileStream); } // Close the document and release resources. From 60b50e93e0c138ea1cafa4e7468b0345e667ee1b Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 4 Jun 2025 17:14:50 +0530 Subject: [PATCH 4/4] 957011 Updated the given feedback. --- .../Multi-color-radial-gradient-fill-in-PDF/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index bd69022a..52729580 100644 --- 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 @@ -27,10 +27,10 @@ // Define gradient colors using RGB (byte values from 0 to 255). List finalGradientColors = new List { - new PdfColor(0, 63, 255), // Blue-ish - new PdfColor(0, 63, 255), // Same blue - new PdfColor(255, 0, 139), // Reddish-purple - new PdfColor(255, 0, 139) // Same reddish-purple + 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.