-
Notifications
You must be signed in to change notification settings - Fork 48
957011 Added sample code for apply Radial Gradient fill to shapes in a PDF document #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
babc005
957011 Added sample code for apply Radial Gradient fill to shapes in …
sameerkhan001 1727e5e
957011 Resolved the given feedback.
sameerkhan001 feffe76
957011 Resolved the given feedback.
sameerkhan001 60b50e9
957011 Updated the given feedback.
sameerkhan001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
.../Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") = "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 |
15 changes: 15 additions & 0 deletions
15
...ET/Multi-color-radial-gradient-fill-in-PDF/Multi-color-radial-gradient-fill-in-PDF.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>Multi-color-radial-gradient-fill-in-PDF</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Empty file.
70 changes: 70 additions & 0 deletions
70
...color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PdfColor> finalGradientColors = new List<PdfColor> | ||
{ | ||
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<float> finalGradientPositions = new List<float> { 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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.