←Select platform

ClipText Method

Summary

Creates a new DocumentPageText from a portion of this text data.

Syntax
C#
C++/CLI
Java
Python
public DocumentPageText ClipText( 
   LeadRectD bounds 
) 
public:  
   DocumentPageText^ ClipText( 
      LeadRectD^ bounds 
   ) 
public DocumentPageText clipText(LeadRectD bounds) 
def ClipText(self,bounds): 

Parameters

bounds

The area to clone. This value is in document coordinates.

Return Value

New DocumentPageText that contains only the characters that are included in bounds.

Remarks

Use this method to create a copy of DocumentPageText that contains only the characters that intersect with a specified rectangle. For example, if your application contains functionality where the user can select a portion of the page using rubber band to extract text from, then you can use ClipText on the page object to return a new object that can be used with BuildWords or BuildText to parse only the words and text of the area.

ClipText works by checking the value of DocumentCharacter.Bounds of each item in Characters by intersecting with bounds. If the value intersects, then it is added to the Characters list of the new object.

If the value of bounds is empty (IsEmpty), then this method returns an exact copy of this DocumentPageText.

bounds must be in document coordinates. Refer to Document Library Coordinate System for more information.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public void DocumentPageTextClipTextExample() 
{ 
   var options = new LoadDocumentOptions(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.doc"), options)) 
   { 
      LeadRect clipPixels = LeadRect.FromLTRB(1337, 300, 1545, 347); 
      LeadRectD clipDocument = document.RectToDocument(clipPixels); 
 
      // get text  
      var page = document.Pages[0]; 
      var pageText = page.GetText().ClipText(clipDocument); 
      if (pageText != null) 
      { 
         pageText.BuildText(); 
         var text = pageText.Text; 
 
         Console.WriteLine(text); 
      } 
      else 
      { 
         Console.WriteLine("Failed!"); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.List; 
import java.util.concurrent.Callable; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.Future; 
import java.util.regex.Pattern; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.annotations.engine.*; 
import leadtools.barcode.*; 
import leadtools.caching.*; 
import leadtools.codecs.*; 
import leadtools.document.*; 
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler; 
import leadtools.document.converter.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void documentPageTextClipTextExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   LEADDocument document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"), 
         options); 
   LeadRect clipPixels = LeadRect.fromLTRB(1337, 300, 1545, 347); 
   LeadRectD clipDocument = document.rectToDocument(clipPixels); 
 
   // get text 
   DocumentPage page = document.getPages().get(0); 
   DocumentPageText pageText = page.getText().clipText(clipDocument); 
   if (pageText != null) { 
      pageText.buildText(); 
      String text = pageText.getText(); 
      System.out.println(text); 
   } else { 
      System.out.println("Failed!"); 
   } 
   assertTrue(pageText != null); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.