From e84c864bc8fd49c72c828c01405365bcfa1a35ed Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Thu, 25 Sep 2025 11:45:03 +0530 Subject: [PATCH] 260120: Added text clipping in PDF layout --- ...Detecting-text-clipping-in-PDF-layouts.sln | 25 +++++++++++ ...ecting-text-clipping-in-PDF-layouts.csproj | 15 +++++++ .../Program.cs | 42 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts.sln create mode 100644 Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Detecting-text-clipping-in-PDF-layouts.csproj create mode 100644 Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Program.cs diff --git a/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts.sln b/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts.sln new file mode 100644 index 00000000..03c5f347 --- /dev/null +++ b/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36408.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +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}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CD58A5D-765C-40AC-BE7A-A1CD873F7173}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D8632971-EA4E-4115-A622-71FA04D6ED24} + EndGlobalSection +EndGlobal diff --git a/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Detecting-text-clipping-in-PDF-layouts.csproj b/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Detecting-text-clipping-in-PDF-layouts.csproj new file mode 100644 index 00000000..b47660b2 --- /dev/null +++ b/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Detecting-text-clipping-in-PDF-layouts.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Detecting_text_clipping_in_PDF_layouts + enable + enable + + + + + + + diff --git a/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Program.cs b/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Program.cs new file mode 100644 index 00000000..958eb271 --- /dev/null +++ b/Text/Detecting-text-clipping-in-PDF-layouts/.NET/Detecting-text-clipping-in-PDF-layouts/Program.cs @@ -0,0 +1,42 @@ +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +// Create a new PDF document +PdfDocument document = new PdfDocument(); + +// Add a page to the document +PdfPage page = document.Pages.Add(); + +// Create PDF graphics for the page +PdfGraphics graphics = page.Graphics; + +// Set the standard font +PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 30); + +// Declare the text to be drawn +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."; + +// Define the bounds within which the text should be drawn +RectangleF border = new RectangleF(0, 0, page.GetClientSize().Width, 150); + +// Draw a rectangle to visualize the layout bounds +graphics.DrawRectangle(PdfPens.Black, border); + +// Initialize the PdfStringLayouter to layout the text +PdfStringLayouter layouter = new PdfStringLayouter(); + +// Layout the text and get the result to check if it fits within the bounds +PdfStringLayoutResult result = layouter.Layout(text, font, new PdfStringFormat(PdfTextAlignment.Center), new SizeF(border.Width, border.Height)); + +// Check if any part of the text was clipped (did not fit within the specified bounds) +if (result.Remainder != null) +{ + // Store the clipped portion of the text for further processing or logging + string remainderText = result.Remainder; + // Output the clipped text to the console for debugging or review + Console.WriteLine("Remainder Text: " + remainderText); +} +// Close the document and release resources +document.Close(true); +