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

Method set_oc

src/__init__.py:6956–6976  ·  view source on GitHub ↗

Attach optional content object to image or form xobject. Args: xref: (int) xref number of an image or form xobject oc: (int) xref number of an OCG or OCMD

(doc: 'Document', xref: int, oc: int)

Source from the content-addressed store, hash-verified

6954 return
6955
6956 def set_oc(doc: 'Document', xref: int, oc: int) -> None:
6957 """Attach optional content object to image or form xobject.
6958
6959 Args:
6960 xref: (int) xref number of an image or form xobject
6961 oc: (int) xref number of an OCG or OCMD
6962 """
6963 if doc.is_closed or doc.is_encrypted:
6964 raise ValueError("document close or encrypted")
6965 t, name = doc.xref_get_key(xref, "Subtype")
6966 if t != "name" or name not in ("/Image", "/Form"):
6967 raise ValueError(f"bad object type at xref {xref}")
6968 if oc > 0:
6969 t, name = doc.xref_get_key(oc, "Type")
6970 if t != "name" or name not in ("/OCG", "/OCMD"):
6971 raise ValueError(f"bad object type at xref {oc}")
6972 if oc == 0 and "OC" in doc.xref_get_keys(xref):
6973 doc.xref_set_key(xref, "OC", "null")
6974 return None
6975 doc.xref_set_key(xref, "OC", f"{oc} 0 R")
6976 return None
6977
6978 def set_ocmd(
6979 doc: 'Document',

Callers

nothing calls this directly

Calls 3

xref_get_keyMethod · 0.80
xref_get_keysMethod · 0.80
xref_set_keyMethod · 0.80

Tested by

no test coverage detected