pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
5.25k stars 499 forks source link

getText("rawdict") returns bytes #428

Closed samuelhalff closed 4 years ago

samuelhalff commented 4 years ago

Please provide all mandatory information!

Describe the bug (mandatory)

Trying to extract rawdict from attached file but getText("rawdict")

To Reproduce (mandatory)

import fitz import json doc = fitz.open("./test_ocr.pdf") page = doc[1] pageTemp = page.getText("rawdict") text = json.dumps(pageTemp, indent=4) file1 = open("./test_result_p1.txt","w") file1.write(text) file1.close()

Expected behavior (optional)

Return rawdict, not bytes.

On other PDFs, for instance PDFs that were generated by WORD, rawdict works fine. But on the attached PDF (just below), i.e. an OCR'rd scanned PDF, it returns nonsensical bytes. test_ocr.pdf

Bytes returned

\x92$I\xba\xb8\x04l\x92$I\xd7\xd1\xfbc\xf2/\x88\xfa\xff~\xbf\x1b\xc5/\x18\xe6GD\x7fPt\xee}\xcc\xca\xcd\x07\x7fB^?hZ\x97\xd6\xb4$5\xba\xc2\x86\x88lh\xae\x9df\xea\xf5\x02&\xb7\xe8z\xb6\x9e\xad\x9d\xe9/Y\r\xed\xe5\xa3\t6\xee\xe7\xd5Say\xee6d~\xfe\x1bm\x94\xe4zP\xb1\x1b\xc0\xf3\xf0\xdf\xef\xa4o\xcd=~P\x1e\x9a\x8f\x16\xe8\xbf\x82?\x8ey\xfcg*\xfd\x0e}\xba\xd2\xcf\xda\nt\x16:\x17\x06\xfe\xac\xc03\xed|9R\xfb\xef\xe9\n\xf9I\xda\xa1\xa3\xbb\xf5\x94\x89\xffu\xd9\xf3\x12\xc1#0\xa2\xbdt\x9a\xad\x97\x18t\'j\xd1\xee,\xfc\xb6\x86\xce\xd5\x13D\xc6\r\xf3\x1e\x9b\xb7?\x97i\xdb\xaa\xbb{(\x1a\xe1{\x8c+\xecC\xaag\x07S\x88\x1a;G\xd98\xee_\x03\xe6\xd0\x94\xc1p\x165\tZ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f4Y\x9d\xfcQ\x01\x11\x9b$\xfd\x05\t\xd8$I\x92>\xa9\xe8\x1bhw\xb7\xa8H.I\xbf]\x026I\x92\xa4\xcf\x89\xfc\xf2\xc6\xd1V\xffk\xef\x0en\x00\x00A\x00\x88\xe9\xfeK;\x01>\xcd\xc5\xb4;@\xeeC\xb0\xc9\xe1w\xc6\x1c\xe0\x9d\xf9\xa3\x10\xc0\x85\x9d\x01\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\xdbK\xb1\x01\x00\xa4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c+Q\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10\'\xd8\x00\x00\xe2\x04\x1b\x00@\x9c\x03\x00\x88\x13l\x00\x00q\x82\r\x00 N\xb0\x01\x00\xc4\t6\x00\x808\xc1\x06\x00\x10w\x00\x86\xff\x81\x15\xb9\xc7\xc2\x81\x00\x00\x00\x00IEND\xaeB\x82'}]}

Your configuration (mandatory)

For example, the output of print(sys.version, "\n", sys.platform, "\n", fitz.__doc__) would be sufficient (for the first two bullets):

PyMuPDF 1.16.10: Python bindings for the MuPDF 1.16.0 library. Version date: 2019-12-21 07:31:32. Built for Python 3.8 on linux (64-bit).

Additional context (optional)

Add any other context about the problem here.

JorjMcKie commented 4 years ago

This is expected, normal behaviour: This PDF page contains 15 blocks, of which one (the last one) is an image block (block type 1). Image blocks contain directory items "image", which is a bytes object. A type I chose for performance and memory size reasons. On the dying Python2 side, images are of type bytearray, so I can see they are no normal strings, Your problem is that you try to convert this to a JSON string, which json does not support out of the box.

You have two options:

  1. Use getText("json"), which under the hood uses getText("dict") and converts any encountered bytes content to base64 strings
  2. Continue to use rawdict but mimic the behaviour of getText("json") for JSON output. This entails defining a class which inherits JSONEncoder like this:
class b64encode(json.JSONEncoder):
    def default(self,s):
        if type(s) is bytes:
            return base64.b64encode(s).decode()

text = json.dumps(page.getText("rawdict"), cls=b64encode, ...)
samuelhalff commented 4 years ago

Thanks a lot for this, very very useful !!