Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

DynaPDF.Parser.FindText

Finds text using the parser.

Component Version macOS Windows Linux Server iOS SDK
DynaPDF 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "DynaPDF.Parser.FindText"; PDF; Text; SearchType; ContinueSearch { ; Left; Bottom; Right; Top } )   More

Parameters

Parameter Description Example Flags
PDF The PDF reference. $pdf
Text The text to find.
SearchType The search type.
Can be a combination of Default, MatchAlways, WholeWord, CaseInSensitive or CaseSensitive.
"CaseInSensitive, WholeWord"
ContinueSearch Whether to start fresh (False) or continue search (true). 0
Left The left coordinate of the rectangle. 0 Optional
Bottom The bottom coordinate of the page. 0 Optional
Right The right coordinate of the page. 595 Optional
Top The top coordinate of the page. 842 Optional

Result

Returns OK or error.

Description

Finds text using the parser.
Searches for text and stores the result so that further editing actions can be applied.

Area must be defined as if the page would be viewed in a PDF viewer. That means in bottom up coordinates and the orientation must be considered (see DynaPDF.GetOrientation). The width and height of a page must be calculated from the crop box if set, or from the media box otherwise (see DynaPDF.GetBBox). Note also that the width and height must be exchanged if the orientation is 90, -90, 270, or -270 degrees.

The page coordinate system is de-rotated since this produces better results and it is much easier to find the location of text in rotated pages.

DynaPDF.Parser.FindText is usually called inside a loop until no more occurrences of the search string can be found. In the first call, continueSearch must be false. That means start at the beginning. The continue searches with continueSearch = true.

Available search types:
TextNumberDescription
Default0Case sensitive search
WholeWord1Only whole words
CaseInSensitive2Case insensitive search
MatchAlways4Return on every single character. Text is ignored when this flag is set.

Examples

Perform find and replace:

# initialize parser
Set Variable [ $OptimizeFlags ; Value: 0 ]
Set Variable [ $r ; Value: MBS( "DynaPDF.Parser.Create"; $pdf; $OptimizeFlags ) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.Parser.SetAltFont"; $pdf; "Helvetica"; 0; 12) ]
#
# Now parse a page
Set Variable [ $r ; Value: MBS("DynaPDF.Parser.ParsePage"; $pdf; 1; "EnableTextSelection") ]
If [ MBS("IsError") ]
    Show Custom Dialog [ "Failed to parse page" ; $r ]
Else
    # Run a find
    Set Variable [ $continueFind ; Value: 0 ]
    Set Variable [ $r ; Value: MBS( "DynaPDF.Parser.FindText"; $pdf; DynaPDF Replace Text::SearchText; "CaseInsensitive"; $continueFind) ]
    If [ $r = 1 ]
        Loop [ Flush: Always ]
            # Do the replace
            Set Variable [ $r ; Value: MBS( "DynaPDF.Parser.ReplaceSelText"; $pdf; DynaPDF Replace Text::ReplaceText) ]
            #
            # Continue search
            Set Variable [ $continueFind ; Value: 1 ]
            Set Variable [ $r ; Value: MBS( "DynaPDF.Parser.FindText"; $pdf; DynaPDF Replace Text::SearchText; "CaseInsensitive"; $continueFind) ]
            Exit Loop If [ $r ≠ 1 ]
        End Loop
        #
        # Save changes back
        Set Variable [ $r ; Value: MBS( "DynaPDF.Parser.WriteToPage"; $pdf; $OptimizeFlags) ]
    End If
End If

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 23th November 2023, last changed 14th December 2023


DynaPDF.Parser.ExtractText - DynaPDF.Parser.Line