Skip to content

Commit f07fea3

Browse files
Merge pull request #1469 from Syncfusion-Content/hotfix/hotfix-v31.1.17
DOCINFRA-2341_merged_using_automation
2 parents b739f84 + 2367acc commit f07fea3

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,143 @@ document.Close(True)
22592259

22602260
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Text/Add-text-encoding-using-standard-PDF-fonts).
22612261

2262+
## Detecting Text Clipping in PDF Layouts
2263+
2264+
Essential PDF provides functionality to determine whether text exceeds the specified layout bounds using the Remainder property of [PdfStringLayoutResult](https://help.syncfusion.com/cr/xamarin/Syncfusion.Pdf.Graphics.PdfStringLayoutResult.html) and [PdfStringLayouter](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfStringLayouter.html). This feature helps identify clipped text and retrieve the remaining portion that doesn't fit within the defined area.
2265+
2266+
The following code example demonstrates how to access the remainder text when the content overflows the given bounds.
2267+
2268+
{% tabs %}
2269+
2270+
{% highlight c# tabtitle="C# [Cross-platform]" %}
2271+
2272+
// Create a new PDF document
2273+
PdfDocument document = new PdfDocument();
2274+
2275+
// Add a page to the document
2276+
PdfPage page = document.Pages.Add();
2277+
2278+
// Create PDF graphics for the page
2279+
PdfGraphics graphics = page.Graphics;
2280+
2281+
// Set the standard font
2282+
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 30);
2283+
2284+
// Declare the text to be drawn
2285+
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.";
2286+
2287+
// Define the bounds within which the text should be drawn
2288+
RectangleF border = new RectangleF(0, 0, page.GetClientSize().Width, 150);
2289+
2290+
// Draw a rectangle to visualize the layout bounds
2291+
graphics.DrawRectangle(PdfPens.Black, border);
2292+
2293+
// Initialize the PdfStringLayouter to layout the text
2294+
PdfStringLayouter layouter = new PdfStringLayouter();
2295+
2296+
// Layout the text and get the result to check if it fits within the bounds
2297+
PdfStringLayoutResult result = layouter.Layout(text, font, new PdfStringFormat(PdfTextAlignment.Center), new SizeF(border.Width, border.Height));
2298+
2299+
// Check if any part of the text was clipped (did not fit within the specified bounds)
2300+
if (result.Remainder != null)
2301+
{
2302+
// Store the clipped portion of the text for further processing or logging
2303+
string remainderText = result.Remainder;
2304+
// Output the clipped text to the console for debugging or review
2305+
Console.WriteLine("Remainder Text: " + remainderText);
2306+
}
2307+
// Close the document and release resources
2308+
document.Close(true);
2309+
2310+
{% endhighlight %}
2311+
2312+
{% highlight c# tabtitle="C# [Windows-specific]" %}
2313+
2314+
// Create a new PDF document
2315+
PdfDocument document = new PdfDocument();
2316+
2317+
// Add a page to the document
2318+
PdfPage page = document.Pages.Add();
2319+
2320+
// Create PDF graphics for the page
2321+
PdfGraphics graphics = page.Graphics;
2322+
2323+
// Set the standard font
2324+
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 30);
2325+
2326+
// Declare the text to be drawn
2327+
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.";
2328+
2329+
// Define the bounds within which the text should be drawn
2330+
RectangleF border = new RectangleF(0, 0, page.GetClientSize().Width, 150);
2331+
2332+
// Draw a rectangle to visualize the layout bounds
2333+
graphics.DrawRectangle(PdfPens.Black, border);
2334+
2335+
// Initialize the PdfStringLayouter to layout the text
2336+
PdfStringLayouter layouter = new PdfStringLayouter();
2337+
2338+
// Layout the text and get the result to check if it fits within the bounds
2339+
PdfStringLayoutResult result = layouter.Layout(text, font, new PdfStringFormat(PdfTextAlignment.Center), new SizeF(border.Width, border.Height));
2340+
2341+
// Check if any part of the text was clipped (did not fit within the specified bounds)
2342+
if (result.Remainder != null)
2343+
{
2344+
// Store the clipped portion of the text for further processing or logging
2345+
string remainderText = result.Remainder;
2346+
// Output the clipped text to the console for debugging or review
2347+
Console.WriteLine("Remainder Text: " + remainderText);
2348+
}
2349+
// Close the document and release resources
2350+
document.Close(true);
2351+
2352+
{% endhighlight %}
2353+
2354+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
2355+
2356+
' Create a new PDF document
2357+
Dim document As New PdfDocument()
2358+
2359+
' Add a page to the document
2360+
Dim page As PdfPage = document.Pages.Add()
2361+
2362+
' Create PDF graphics for the page
2363+
Dim graphics As PdfGraphics = page.Graphics
2364+
2365+
' Set the standard font
2366+
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 30)
2367+
2368+
' Declare the text to be drawn
2369+
Dim text As String = "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."
2370+
2371+
' Define the bounds within which the text should be drawn
2372+
Dim border As New RectangleF(0, 0, page.GetClientSize().Width, 150)
2373+
2374+
' Draw a rectangle to visualize the layout bounds
2375+
graphics.DrawRectangle(PdfPens.Black, border)
2376+
2377+
' Initialize the PdfStringLayouter to layout the text
2378+
Dim layouter As New PdfStringLayouter()
2379+
2380+
' Layout the text and get the result to check if it fits within the bounds
2381+
Dim result As PdfStringLayoutResult = layouter.Layout(text, font, New PdfStringFormat(PdfTextAlignment.Center), New SizeF(border.Width, border.Height))
2382+
2383+
' Check if any part of the text was clipped (did not fit within the specified bounds)
2384+
If result.Remainder IsNot Nothing Then
2385+
' Store the clipped portion of the text for further processing or logging
2386+
Dim remainderText As String = result.Remainder
2387+
' Output the clipped text to the console for debugging or review
2388+
Console.WriteLine("Remainder Text: " & remainderText)
2389+
End If
2390+
' Close the document and release resources
2391+
document.Close(True)
2392+
2393+
{% endhighlight %}
2394+
2395+
{% endtabs %}
2396+
2397+
A complete working sample is available for download on GitHub.
2398+
22622399
## Customizing TrueType fonts in a PDF document
22632400

22642401
The Syncfusion<sup>&reg;</sup> PDF library provides extensive options for customizing TrueType font settings in PDF documents through the `PdfFontSettings` class. Users can modify font size, style, and choose to embed or subset fonts. Additionally, measurement settings can be adjusted using a floating factor for precise control over font rendering.

0 commit comments

Comments
 (0)