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

Class TextPage

src/__init__.py:16377–16720  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16375
16376
16377class TextPage:
16378
16379 def __init__(self, *args):
16380 if args_match(args, mupdf.FzRect):
16381 mediabox = args[0]
16382 self.this = mupdf.FzStextPage( mediabox)
16383 elif args_match(args, mupdf.FzStextPage):
16384 self.this = args[0]
16385 else:
16386 raise Exception(f'Unrecognised args: {args}')
16387 self.thisown = True
16388 self.parent = None
16389
16390 def _extractText(self, format_):
16391 this_tpage = self.this
16392 res = mupdf.fz_new_buffer(1024)
16393 out = mupdf.FzOutput( res)
16394 # fixme: mupdfwrap.py thinks fz_output is not copyable, possibly
16395 # because there is no .refs member visible and no fz_keep_output() fn,
16396 # although there is an fz_drop_output(). So mupdf.fz_new_output_with_buffer()
16397 # doesn't convert the returned fz_output* into a mupdf.FzOutput.
16398 #out = mupdf.FzOutput(out)
16399 if format_ == 1:
16400 mupdf.fz_print_stext_page_as_html(out, this_tpage, 0)
16401 elif format_ == 3:
16402 mupdf.fz_print_stext_page_as_xml(out, this_tpage, 0)
16403 elif format_ == 4:
16404 mupdf.fz_print_stext_page_as_xhtml(out, this_tpage, 0)
16405 else:
16406 JM_print_stext_page_as_text(res, this_tpage)
16407 out.fz_close_output()
16408 text = JM_EscapeStrFromBuffer(res)
16409 return text
16410
16411 def _getNewBlockList(self, page_dict, raw):
16412 JM_make_textpage_dict(self.this, page_dict, raw)
16413
16414 def _textpage_dict(self, raw=False):
16415 page_dict = {"width": self.rect.width, "height": self.rect.height}
16416 self._getNewBlockList(page_dict, raw)
16417 return page_dict
16418
16419 def extractBLOCKS(self):
16420 """Return a list with text block information."""
16421 if 1 or g_use_extra:
16422 return extra.extractBLOCKS(self.this)
16423 block_n = -1
16424 this_tpage = self.this
16425 tp_rect = mupdf.FzRect(this_tpage.m_internal.mediabox)
16426 res = mupdf.fz_new_buffer(1024)
16427 lines = []
16428 for block in this_tpage:
16429 block_n += 1
16430 blockrect = mupdf.FzRect(mupdf.FzRect.Fixed_EMPTY)
16431 if block.m_internal.type == mupdf.FZ_STEXT_BLOCK_TEXT:
16432 mupdf.fz_clear_buffer(res) # set text buffer to empty
16433 line_n = -1
16434 last_char = 0

Callers 2

get_textpageMethod · 0.85
get_textpageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…