You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md
+137Lines changed: 137 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2259,6 +2259,143 @@ document.Close(True)
2259
2259
2260
2260
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).
2261
2261
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
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
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
A complete working sample is available for download on GitHub.
2398
+
2262
2399
## Customizing TrueType fonts in a PDF document
2263
2400
2264
2401
The Syncfusion<sup>®</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