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

Method extractRAWJSON

src/__init__.py:16569–16588  ·  view source on GitHub ↗

Return 'extractRAWDICT' converted to JSON format.

(self, cb=None, sort=False)

Source from the content-addressed store, hash-verified

16567 return val
16568
16569 def extractRAWJSON(self, cb=None, sort=False) -> str:
16570 """Return 'extractRAWDICT' converted to JSON format."""
16571 import base64
16572 import json
16573 val = self._textpage_dict(raw=True)
16574
16575 class b64encode(json.JSONEncoder):
16576 def default(self,s):
16577 if type(s) in (bytes, bytearray):
16578 return base64.b64encode(s).decode()
16579
16580 if cb is not None:
16581 val["width"] = cb.width
16582 val["height"] = cb.height
16583 if sort:
16584 blocks = val["blocks"]
16585 blocks.sort(key=lambda b: (b["bbox"][3], b["bbox"][0]))
16586 val["blocks"] = blocks
16587 val = json.dumps(val, separators=(",", ":"), cls=b64encode, indent=1)
16588 return val
16589
16590 def extractSelection(self, pointa, pointb):
16591 a = JM_point_from_py(pointa)

Callers 2

get_textFunction · 0.80
get_textFunction · 0.80

Calls 1

_textpage_dictMethod · 0.95

Tested by

no test coverage detected