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

Method extractJSON

src/__init__.py:16535–16555  ·  view source on GitHub ↗

Return 'extractDICT' converted to JSON format.

(self, cb=None, sort=False)

Source from the content-addressed store, hash-verified

16533 return rc
16534
16535 def extractJSON(self, cb=None, sort=False) -> str:
16536 """Return 'extractDICT' converted to JSON format."""
16537 import base64
16538 import json
16539 val = self._textpage_dict(raw=False)
16540
16541 class b64encode(json.JSONEncoder):
16542 def default(self, s):
16543 if type(s) in (bytes, bytearray):
16544 return base64.b64encode(s).decode()
16545
16546 if cb is not None:
16547 val["width"] = cb.width
16548 val["height"] = cb.height
16549 if sort:
16550 blocks = val["blocks"]
16551 blocks.sort(key=lambda b: (b["bbox"][3], b["bbox"][0]))
16552 val["blocks"] = blocks
16553
16554 val = json.dumps(val, separators=(",", ":"), cls=b64encode, indent=1)
16555 return val
16556
16557 def extractRAWDICT(self, cb=None, sort=False) -> dict:
16558 """Return page content as a Python dict of images and text characters."""

Callers 2

get_textFunction · 0.80
get_textFunction · 0.80

Calls 1

_textpage_dictMethod · 0.95

Tested by

no test coverage detected