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

Function set_oc

src_classic/utils.py:4542–4562  ·  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

4540
4541
4542def set_oc(doc: Document, xref: int, oc: int) -> None:
4543 """Attach optional content object to image or form xobject.
4544
4545 Args:
4546 xref: (int) xref number of an image or form xobject
4547 oc: (int) xref number of an OCG or OCMD
4548 """
4549 if doc.is_closed or doc.is_encrypted:
4550 raise ValueError("document close or encrypted")
4551 t, name = doc.xref_get_key(xref, "Subtype")
4552 if t != "name" or name not in ("/Image", "/Form"):
4553 raise ValueError("bad object type at xref %i" % xref)
4554 if oc > 0:
4555 t, name = doc.xref_get_key(oc, "Type")
4556 if t != "name" or name not in ("/OCG", "/OCMD"):
4557 raise ValueError("bad object type at xref %i" % oc)
4558 if oc == 0 and "OC" in doc.xref_get_keys(xref):
4559 doc.xref_set_key(xref, "OC", "null")
4560 return None
4561 doc.xref_set_key(xref, "OC", "%i 0 R" % oc)
4562 return None
4563
4564
4565def set_ocmd(

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…