←Select platform

EndPosition Property

Summary

Indicates one of the bounds of the Find Text operation.

Syntax
C#
C++/CLI
public DocumentViewerTextPosition EndPosition { get; set; } 
public:  
   property DocumentViewerTextPosition^ EndPosition 
   { 
      DocumentViewerTextPosition^ get() 
      void set(DocumentViewerTextPosition^ value) 
   } 

Property Value

A DocumentViewerTextPosition object indicating the page number and index of the bottom of the text search. The default value is null, which indicates the bottom of the last page of the document.

Remarks

EndPosition allows DocumentViewerText.Find to have an end bound. Its specification with BeginPosition also decides the direction of the search.

If EndPosition is found to be "greater than" BeginPosition - meaning a higher page number or character index - the search will be conducted in the "forward" direction, incrementing through the character indices and pages from BeginPosition to EndPosition. Otherwise, the search will be conducted in a "backward" direction, decrementing through the pages and character indices, but still from the BeginPosition to the EndPosition. Thus, to change direction between calls to DocumentViewerText.Find, swap the two properties.

Since a page's text may not yet be parsed when the search bounds are being chosen, both BeginPosition and EndPosition can take -1 as the value for DocumentViewerTextPosition.CharacterIndex. This value will be internally resolved to the index of the final character of the page if and when the page's text is retrieved. If DocumentViewerText.AutoGetText is false, the -1 will not resolve to a real index and the search will return no results for that page.

See Start as a way to change the start of the search from BeginPosition while maintaining BeginPosition as a bound. If FindAll or Loop are true, this could internally create two searches:

  1. Search from start to EndPosition.
  2. If start from (1) was not BeginPosition, and FindAll or Loop is true, search from BeginPosition to start – 1.

The default value is null, meaning the bottom of the final page.

For more information, refer to DocumentViewerText.Find.

History

19.0.0.49

Added - Replaces PageNumber and GoToNextPage

Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Document; 
using Leadtools.Document.Viewer; 
using Leadtools.Codecs; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
 
 
var text = _documentViewer.Text; 
 
// Make sure we get the page text if necessary 
text.AutoGetText = true; 
 
// We will find all matches of "LEAD", ignoring the case 
var options = new DocumentViewerFindText(); 
 
// The text 
options.Text = "LEAD"; 
// Ignore case 
options.MatchCase = false; 
// Any word that contains the phrase 
options.WholeWordsOnly = false; 
 
// Find all results in the bounds, not just the first 
options.FindAll = true; 
 
// Highlight the results in the View 
options.RenderResults = true; 
// Optionally change the highlight color 
//DocumentViewerText.FoundTextBrush = new SolidBrush(Color.FromArgb(52, Color.Brown)); 
 
// Set the bounds 
bool isFindingNext = true; 
// We set the bounds as the whole document, but below we can specify to start wherever text is selected 
// or at the current page 
var topOfFirstPage = DocumentViewerTextPosition.CreateBeginOfPage(1); 
var bottomOfLastPage = DocumentViewerTextPosition.CreateEndOfPage(_documentViewer.PageCount); 
if (isFindingNext) 
{ 
   // Make the beginning bound "higher up" the page so we search "down" the page. 
   options.BeginPosition = topOfFirstPage; 
   options.EndPosition = bottomOfLastPage; 
} 
else 
{ 
   // Make the beginning bound "lower down" the page so we search "up" the page. 
   options.BeginPosition = bottomOfLastPage; 
   options.EndPosition = topOfFirstPage; 
} 
 
// Select the first result in the View (automatically scrolls View also) 
options.SelectFirstResult = true; 
 
if (text.HasAnySelectedText) 
{ 
   // Setting this value to AfterSelection allows us to search forward from the selection, so multiple 
   // uses of this same options object will cycle us through all the matches! 
   // (If no selected text actually exists, search will default to beginPosition.) 
   options.Start = DocumentViewerFindTextStart.AfterSelection; 
} 
else 
{ 
   // We could start at the begin position, but it makes more UI sense to start from the user's current page. 
   // Search will loop back around to the begin position - this just changes the starting point and order of results. 
   options.Start = DocumentViewerFindTextStart.ManualPosition; 
   if (isFindingNext) 
      options.ManualStartPosition = DocumentViewerTextPosition.CreateBeginOfPage(_documentViewer.CurrentPageNumber); 
   else 
      options.ManualStartPosition = DocumentViewerTextPosition.CreateEndOfPage(_documentViewer.CurrentPageNumber); 
} 
 
// If we were just looking for the first match, we could use "Loop" to loop around 
// if we found nothing between the start position and the end bound. 
//options.Loop = true; 
 
// You will likely want to clear the previous highlighted results 
// on the screen so only our new results will show. 
text.ClearRenderedFoundText(); 
 
// Search 
var results = text.Find(options); 
int resultsCount = results != null ? results.Count : 0; 
 
if (resultsCount > 0) 
   Console.WriteLine(string.Format("Found {0} results", resultsCount)); 
else 
   Console.WriteLine("No matches found."); 
Requirements

Target Platforms

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

Leadtools.Document.Viewer.WinForms Assembly

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