Skip to content
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}") = "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
Original file line number Diff line number Diff line change
@@ -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<PdfColor> gradientColors = new List<PdfColor>
{
Color.CornflowerBlue,
Color.MediumPurple,
Color.DeepPink
};

List<float> gradientPositions = new List<float> { 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);
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>Radial_gradient_rectangle_in_PDF</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Loading