Get PDF dict key value of object at 'xref'.
(self, xref, key)
| 7911 | doc.xref_set_key(target, key, item[1]) |
| 7912 | |
| 7913 | def xref_get_key(self, xref, key): |
| 7914 | """Get PDF dict key value of object at 'xref'.""" |
| 7915 | pdf = _as_pdf_document(self) |
| 7916 | xreflen = mupdf.pdf_xref_len(pdf) |
| 7917 | if not _INRANGE(xref, 1, xreflen-1) and xref != -1: |
| 7918 | raise ValueError( MSG_BAD_XREF) |
| 7919 | if xref > 0: |
| 7920 | obj = mupdf.pdf_load_object(pdf, xref) |
| 7921 | else: |
| 7922 | obj = mupdf.pdf_trailer(pdf) |
| 7923 | if not obj.m_internal: |
| 7924 | return ("null", "null") |
| 7925 | subobj = mupdf.pdf_dict_getp(obj, key) |
| 7926 | if not subobj.m_internal: |
| 7927 | return ("null", "null") |
| 7928 | text = None |
| 7929 | if mupdf.pdf_is_indirect(subobj): |
| 7930 | type = "xref" |
| 7931 | text = f"{mupdf.pdf_to_num(subobj):d} 0 R" |
| 7932 | elif mupdf.pdf_is_array(subobj): |
| 7933 | type = "array" |
| 7934 | elif mupdf.pdf_is_dict(subobj): |
| 7935 | type = "dict" |
| 7936 | elif mupdf.pdf_is_int(subobj): |
| 7937 | type = "int" |
| 7938 | text = f"{mupdf.pdf_to_int(subobj):d}" |
| 7939 | elif mupdf.pdf_is_real(subobj): |
| 7940 | type = "float" |
| 7941 | elif mupdf.pdf_is_null(subobj): |
| 7942 | type = "null" |
| 7943 | text = "null" |
| 7944 | elif mupdf.pdf_is_bool(subobj): |
| 7945 | type = "bool" |
| 7946 | if mupdf.pdf_to_bool(subobj): |
| 7947 | text = "true" |
| 7948 | else: |
| 7949 | text = "false" |
| 7950 | elif mupdf.pdf_is_name(subobj): |
| 7951 | type = "name" |
| 7952 | text = f"/{mupdf.pdf_to_name(subobj)}" |
| 7953 | elif mupdf.pdf_is_string(subobj): |
| 7954 | type = "string" |
| 7955 | text = JM_UnicodeFromStr(mupdf.pdf_to_text_string(subobj)) |
| 7956 | else: |
| 7957 | type = "unknown" |
| 7958 | if text is None: |
| 7959 | res = JM_object_to_buffer(subobj, 1, 0) |
| 7960 | text = JM_UnicodeFromBuffer(res) |
| 7961 | return (type, text) |
| 7962 | |
| 7963 | def xref_get_keys(self, xref): |
| 7964 | """Get the keys of PDF dict object at 'xref'. Use -1 for the PDF trailer.""" |