Skip to content

Commit faff61a

Browse files
committed
261980: Added code example for set and restore clipping mechanism in PDF document
1 parent 6542a4f commit faff61a

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36616.10 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clipping-and-graphics-state", "Clipping-and-graphics-state\Clipping-and-graphics-state.csproj", "{D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {820F8B8B-A228-4044-AE9F-406099112325}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Clipping_and_graphics_state</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
20.9 KB
Loading

Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
5+
// Create a new PDF document
6+
using (PdfDocument document = new PdfDocument())
7+
{
8+
// Add a page to the document
9+
PdfPage page = document.Pages.Add();
10+
// Get the graphics object for the page
11+
PdfGraphics graphics = page.Graphics;
12+
// Open the image file as a stream
13+
using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Input.png"), FileMode.Open, FileAccess.Read);
14+
// Load the image from the stream
15+
PdfBitmap image = new PdfBitmap(imageStream);
16+
// Save the current graphics state (to restore later)
17+
PdfGraphicsState state = graphics.Save();
18+
// Define a rectangular clipping region
19+
RectangleF clipRect = new RectangleF(50, 50, 200, 100);
20+
graphics.SetClip(clipRect);
21+
// Draw the image — only the part within the clipping region will be visible
22+
graphics.DrawImage(image, new RectangleF(40, 60, 150, 80));
23+
// Restore the graphics state to remove the clipping region
24+
graphics.Restore(state);
25+
// Draw the image again — this time the full image will be visible
26+
graphics.DrawImage(image, new RectangleF(60, 160, 150, 80));
27+
// Save the PDF document
28+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
29+
}

0 commit comments

Comments
 (0)