Frameworks
Integrations
Mendix
SharePoint
Modular UI
Legacy UI
AnnotationManager
Annotation Types
Customize
Version 11
Version 10
v10.12
v10.11
v10.10
v10.9
v10.8
v10.7
v10.6
v10.5
v10.4
v10.3
v10.2
v10.1
v10.0
Version 8
v8.12
v8.11
v8.10
v8.9
v8.8
v8.7
v8.6
v8.5
v8.4
v8.3
v8.2
v8.1
v8.0
Version 7
Version 6
v6.3
v6.2
v6.1
v6.0
Version 5
Version 4
Version 3
Version 2
WebViewer Server
WebViewer BIM
It's possible to load a document and search through its content without rendering the document in WebViewer. This can be helpful for performance as the document doesn't need to be rendered to search through it. This feature is provided by the TextSearch
class and an example can be found below.
This guide uses the full API without a viewer.
Like other PDFNet code, start by using runWithCleanup to run the code. Afterwards, create new TextSearch
and PDFDoc
objects (in the above sample, we used createFromURL but other methods work as well). To start the search, call the begin method on the TextSearch
object. begin
takes in the following parameters:
doc
: PDFDoc
object of the document to searchsearch_pattern
: text string or regex pattern to searchmode
: A number that encodes the search options, generated by bitwise ORing options togetherstart_page
: optional page number to start searching on. Defaults to 1end_page
: optional page number for when to stop searching. Defaults to last pageThe mode
input is a number used for controlling how the search behaves. It can be created by using the "|" bitwise OR operation on the desired modes to use. All the mode can be found on the PDFNet.TextSearch.Mode
object, they are:
e_reg_expression
: If set, treat the search pattern as a regular expressione_case_sensitive
: If set, the text searched must match case of the search patterne_whole_word
: If set, only match whole wordse_search_up
: If set, search from the last page of the document backwards to the firste_page_stop
: If set, will return a 'result' whenever a page has been searchede_highlight
: If set, will return the quads of found resultse_ambient_string
: If set, will return text around the search patternAfter calling 'begin', calling run will begin searching the document. It'll return a promise that resolves to a 'result' object with the with the following properties
e_ambient_string
: If using e_ambient_string
mode, return characters surrounding the search patterncode
: a PDFNet.TextSearch.ResultCode
indicating whether the result is from a search term being found or the text search finished searching through a page or the documente_found
: search pattern founde_page
: done searching a pagee_done
: done searching the whole documenthighlights
: a Highlights objectout_str
: The string that matches the search term. Since sometimes case doesn't matter or regular expression could be use for searching, this could be different from the original search termpage_num
: The page the result was found onIf using e_page_stop
mode, run
will return a result whenever it has finished searching a page. Otherwise, it'll only return results when a match has been found or if the document has finished searching. After the first search result is returned, keep on calling run
to get the next result until the search is complete.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales