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

Method xref_get_key

src/__init__.py:7913–7961  ·  view source on GitHub ↗

Get PDF dict key value of object at 'xref'.

(self, xref, key)

Source from the content-addressed store, hash-verified

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."""

Callers 15

embfile_infoMethod · 0.95
markinfoMethod · 0.95
pagelayoutMethod · 0.95
pagemodeMethod · 0.95
xref_is_fontMethod · 0.95
xref_is_imageMethod · 0.95
xref_is_xobjectMethod · 0.95
get_ocMethod · 0.80
scrubMethod · 0.80
set_metadataMethod · 0.80
set_ocMethod · 0.80
get_old_widthsMethod · 0.80

Calls 6

_as_pdf_documentFunction · 0.85
_INRANGEFunction · 0.85
JM_UnicodeFromStrFunction · 0.85
JM_object_to_bufferFunction · 0.85
JM_UnicodeFromBufferFunction · 0.85
pdf_trailerMethod · 0.80

Tested by 11

valuesFunction · 0.64
test_rotation1Function · 0.64
test_trailerFunction · 0.64
test_valid_nameFunction · 0.64
test_extract_imageFunction · 0.64
test_pageboxesFunction · 0.64
test_4141Function · 0.64
test_erase_metaFunction · 0.64
bbox_countFunction · 0.64
test_2736Function · 0.64
getFunction · 0.64