Skip to content

Commit e84c864

Browse files
committed
260120: Added text clipping in PDF layout
1 parent 635fa6a commit e84c864

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-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.36408.4 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Detecting-text-clipping-in-PDF-layouts", "Detecting-text-clipping-in-PDF-layouts\Detecting-text-clipping-in-PDF-layouts.csproj", "{8CD58A5D-765C-40AC-BE7A-A1CD873F7173}"
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+
{8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.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 = {D8632971-EA4E-4115-A622-71FA04D6ED24}
24+
EndGlobalSection
25+
EndGlobal
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>Detecting_text_clipping_in_PDF_layouts</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>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
5+
// Create a new PDF document
6+
PdfDocument document = new PdfDocument();
7+
8+
// Add a page to the document
9+
PdfPage page = document.Pages.Add();
10+
11+
// Create PDF graphics for the page
12+
PdfGraphics graphics = page.Graphics;
13+
14+
// Set the standard font
15+
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 30);
16+
17+
// Declare the text to be drawn
18+
string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";
19+
20+
// Define the bounds within which the text should be drawn
21+
RectangleF border = new RectangleF(0, 0, page.GetClientSize().Width, 150);
22+
23+
// Draw a rectangle to visualize the layout bounds
24+
graphics.DrawRectangle(PdfPens.Black, border);
25+
26+
// Initialize the PdfStringLayouter to layout the text
27+
PdfStringLayouter layouter = new PdfStringLayouter();
28+
29+
// Layout the text and get the result to check if it fits within the bounds
30+
PdfStringLayoutResult result = layouter.Layout(text, font, new PdfStringFormat(PdfTextAlignment.Center), new SizeF(border.Width, border.Height));
31+
32+
// Check if any part of the text was clipped (did not fit within the specified bounds)
33+
if (result.Remainder != null)
34+
{
35+
// Store the clipped portion of the text for further processing or logging
36+
string remainderText = result.Remainder;
37+
// Output the clipped text to the console for debugging or review
38+
Console.WriteLine("Remainder Text: " + remainderText);
39+
}
40+
// Close the document and release resources
41+
document.Close(true);
42+

0 commit comments

Comments
 (0)