MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / search_for

Function search_for

src_classic/utils.py:426–463  ·  view source on GitHub ↗

Search for a string on a page. Args: text: string to be searched for clip: restrict search to this rectangle quads: (bool) return quads instead of rectangles flags: bit switches, default: join hyphened words textpage: a pre-created TextPage Returns:

(*args, **kwargs)

Source from the content-addressed store, hash-verified

424
425
426def search_for(*args, **kwargs) -> list:
427 """Search for a string on a page.
428
429 Args:
430 text: string to be searched for
431 clip: restrict search to this rectangle
432 quads: (bool) return quads instead of rectangles
433 flags: bit switches, default: join hyphened words
434 textpage: a pre-created TextPage
435 Returns:
436 a list of rectangles or quads, each containing one occurrence.
437 """
438 if len(args) != 2:
439 raise ValueError("bad number of positional parameters")
440 page, text = args
441 quads = kwargs.get("quads", 0)
442 clip = kwargs.get("clip")
443 textpage = kwargs.get("textpage")
444 if clip != None:
445 clip = Rect(clip)
446 flags = kwargs.get(
447 "flags",
448 TEXT_DEHYPHENATE
449 | TEXT_PRESERVE_WHITESPACE
450 | TEXT_PRESERVE_LIGATURES
451 | TEXT_MEDIABOX_CLIP,
452 )
453
454 CheckParent(page)
455 tp = textpage
456 if tp is None:
457 tp = page.get_textpage(clip=clip, flags=flags) # create TextPage
458 elif getattr(tp, "parent") != page:
459 raise ValueError("not a textpage of this page")
460 rlist = tp.search(text, quads=quads)
461 if textpage is None:
462 del tp
463 return rlist
464
465
466def search_page_for(

Callers

nothing calls this directly

Calls 5

RectClass · 0.85
CheckParentFunction · 0.85
searchMethod · 0.80
getMethod · 0.45
get_textpageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…