Show existing optional content groups.
(self)
| 4915 | return rc |
| 4916 | |
| 4917 | def get_ocgs(self): |
| 4918 | """Show existing optional content groups.""" |
| 4919 | ci = mupdf.pdf_new_name( "CreatorInfo") |
| 4920 | pdf = _as_pdf_document(self) |
| 4921 | ocgs = mupdf.pdf_dict_getl( |
| 4922 | mupdf.pdf_dict_get( mupdf.pdf_trailer( pdf), PDF_NAME('Root')), |
| 4923 | PDF_NAME('OCProperties'), |
| 4924 | PDF_NAME('OCGs'), |
| 4925 | ) |
| 4926 | rc = dict() |
| 4927 | if not mupdf.pdf_is_array( ocgs): |
| 4928 | return rc |
| 4929 | n = mupdf.pdf_array_len( ocgs) |
| 4930 | for i in range(n): |
| 4931 | ocg = mupdf.pdf_array_get( ocgs, i) |
| 4932 | xref = mupdf.pdf_to_num( ocg) |
| 4933 | name = mupdf.pdf_to_text_string( mupdf.pdf_dict_get( ocg, PDF_NAME('Name'))) |
| 4934 | obj = mupdf.pdf_dict_getl( ocg, PDF_NAME('Usage'), ci, PDF_NAME('Subtype')) |
| 4935 | usage = None |
| 4936 | if obj.m_internal: |
| 4937 | usage = mupdf.pdf_to_name( obj) |
| 4938 | intents = list() |
| 4939 | intent = mupdf.pdf_dict_get( ocg, PDF_NAME('Intent')) |
| 4940 | if intent.m_internal: |
| 4941 | if mupdf.pdf_is_name( intent): |
| 4942 | intents.append( mupdf.pdf_to_name( intent)) |
| 4943 | elif mupdf.pdf_is_array( intent): |
| 4944 | m = mupdf.pdf_array_len( intent) |
| 4945 | for j in range(m): |
| 4946 | o = mupdf.pdf_array_get( intent, j) |
| 4947 | if mupdf.pdf_is_name( o): |
| 4948 | intents.append( mupdf.pdf_to_name( o)) |
| 4949 | if mupdf_version_tuple >= (1, 26, 11): |
| 4950 | resource_stack = mupdf.PdfResourceStack() |
| 4951 | hidden = mupdf.pdf_is_ocg_hidden( pdf, resource_stack, usage, ocg) |
| 4952 | else: |
| 4953 | hidden = mupdf.pdf_is_ocg_hidden( pdf, mupdf.PdfObj(), usage, ocg) |
| 4954 | item = { |
| 4955 | "name": name, |
| 4956 | "intent": intents, |
| 4957 | "on": not hidden, |
| 4958 | "usage": usage, |
| 4959 | } |
| 4960 | temp = xref |
| 4961 | rc[ temp] = item |
| 4962 | return rc |
| 4963 | |
| 4964 | def get_ocmd(doc: 'Document', xref: int) -> dict: |
| 4965 | """Return the definition of an OCMD (optional content membership dictionary). |