# SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved.
# Non-Commercial Freeware and Commercial Software.
# This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project.
# The latest version of the code is available on the site www.pullenti.ru

import typing
from pullenti.unisharp.Utils import Utils
from pullenti.unisharp.Misc import RefOutArgWrapper
from pullenti.unisharp.Streams import Stream

from pullenti.unitext.internal.pdf.PdfObject import PdfObject
from pullenti.unitext.internal.pdf.PdfReference import PdfReference
from pullenti.unitext.internal.pdf.PdfArray import PdfArray
from pullenti.unitext.internal.pdf.PdfIntValue import PdfIntValue
from pullenti.unitext.internal.pdf.PdfDictionary import PdfDictionary
from pullenti.unitext.internal.pdf.PdfStream import PdfStream

class PdfFile(PdfObject):
    
    def __init__(self) -> None:
        super().__init__()
        self.root_object = None
        self.info = None
        self.encrypt = None
        self.pages = list()
        self.all_resources = list()
        self.objs = None
        self.trailer = None;
        self.__m_stream = None
        self.__m_head = None;
        self.__m_indirect_objs = list()
        self.__m_indirect_obj_disp = list()
    
    def open0_(self, file_name : str, file_content : bytearray=None) -> None:
        self.root_object = (None)
        self.info = (None)
        if (self.__m_stream is not None): 
            self.__m_stream.close()
        self.__m_stream = PdfStream(file_name, file_content)
        self.__m_head = self.__m_stream.read_head()
        hpos = self.__m_stream.position
        if (self.__read_xrefs()): 
            pass
        else: 
            i = 0
            root_obj = None
            info_obj = None
            self.__m_stream.position = hpos
            while True:
                i = self.__m_stream.peek_solid_byte()
                if (i < 0): 
                    break
                ch = i
                p0 = self.__m_stream.position
                id0__ = 0
                v = 0
                is_obj = False
                str0_ = None
                obj = None
                if ((chr(ch)) >= '0' and (chr(ch)) <= '9'): 
                    wrapid178 = RefOutArgWrapper(0)
                    wrapv179 = RefOutArgWrapper(0)
                    is_obj = self.__m_stream.try_read_id_and_version(False, wrapid178, wrapv179)
                    id0__ = wrapid178.value
                    v = wrapv179.value
                if (is_obj): 
                    obj = (None)
                    try: 
                        obj = self.__m_stream.parse_object(self, False)
                    except Exception as ex: 
                        pass
                    if (obj is None): 
                        self.__m_stream.position = self.__m_stream.position + 1
                        continue
                    obj.id0_ = id0__
                    obj.version = v
                    obj.source_file = self
                    self.__add_obj(id0__, obj)
                    str0_ = self.__m_stream.read_word(False)
                    continue
                str0_ = self.__m_stream.read_word(False)
                if (str0_ == "xref"): 
                    i1 = 0
                    str0_ = self.__m_stream.read_word(False)
                    wrapi1182 = RefOutArgWrapper(0)
                    inoutres183 = Utils.tryParseInt(str0_, wrapi1182)
                    i1 = wrapi1182.value
                    if (inoutres183): 
                        i2 = 0
                        str0_ = self.__m_stream.read_word(False)
                        wrapi2180 = RefOutArgWrapper(0)
                        inoutres181 = Utils.tryParseInt(str0_, wrapi2180)
                        i2 = wrapi2180.value
                        if (inoutres181): 
                            if (i2 > i1): 
                                self.__m_stream.position = self.__m_stream.position + (((i2 - i1)) * 20)
                    while True:
                        str0_ = self.__m_stream.read_word(False)
                        if (Utils.isNullOrEmpty(str0_) or str0_ == "trailer"): 
                            break
                if (str0_ == "trailer"): 
                    i = self.__m_stream.peek_solid_byte()
                    if (((i)) < 0): 
                        break
                    ch = (i)
                    if ((chr(ch)) != '<'): 
                        continue
                    self.__m_stream.position = self.__m_stream.position + 1
                    i = self.__m_stream.read_byte()
                    if (((i)) < 0): 
                        break
                    ch = (i)
                    if ((chr(ch)) != '<'): 
                        break
                    self.trailer = PdfDictionary()
                    self.trailer.source_file = self
                    self.trailer._post_parse(self.__m_stream)
                    if (root_obj is None): 
                        root_obj = self.trailer.get_object("Root", True)
                    if (info_obj is None): 
                        info_obj = self.trailer.get_object("Info", True)
                    if (self.trailer.get_object("Encrypt", True) is not None): 
                        self.encrypt = self.trailer.get_dictionary("Encrypt", None)
                    continue
                pos = self.__m_stream.position
                obj = self.__m_stream.parse_object(self, False)
                if (pos == (self.__m_stream.position)): 
                    self.__m_stream.position = self.__m_stream.position + 1
            if (root_obj is not None): 
                self.root_object = (Utils.asObjectOrNull(self.get_object(root_obj.id0_), PdfDictionary))
            if (info_obj is not None): 
                self.info = (Utils.asObjectOrNull(self.get_object(info_obj.id0_), PdfDictionary))
        i = 1
        while i < len(self.__m_indirect_objs): 
            if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                if (self.__m_indirect_objs[i].is_type_item("ObjStm")): 
                    if (not self.__read_obj_stm(Utils.asObjectOrNull(self.__m_indirect_objs[i], PdfDictionary))): 
                        if (self.__check_encrypt()): 
                            return
            i += 1
        is_linearized = False
        if (self.root_object is None): 
            i = 1
            while i < len(self.__m_indirect_objs): 
                if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                    if (self.__m_indirect_objs[i].get_object("Linearized", False) is not None): 
                        is_linearized = True
                        break
                i += 1
        self.__read_all_resources()
        if (is_linearized): 
            first_page = None
            pos0 = self.__m_stream.length
            i = 1
            while i < len(self.__m_indirect_objs): 
                if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                    dic = Utils.asObjectOrNull(self.__m_indirect_objs[i], PdfDictionary)
                    if (dic.is_type_item("Page")): 
                        self.pages.append(dic)
                        dic.page_num = len(self.pages)
                        if (dic._m_file_pos > 0 and (dic._m_file_pos < pos0)): 
                            first_page = dic
                            pos0 = dic._m_file_pos
                    elif (dic.is_type_item("Catalog")): 
                        self.root_object = dic
                    elif (dic.is_type_item("Info")): 
                        self.info = dic
                i += 1
            if (self.root_object is not None): 
                self.pages.clear()
                self.root_object.get_all_pages(self.pages)
            elif (first_page is not None and self.pages[0] != first_page): 
                self.pages.remove(first_page)
                self.pages.insert(0, first_page)
            return
        if (self.root_object is None): 
            i = 1
            while i < len(self.__m_indirect_objs): 
                if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                    if (self.__m_indirect_objs[i].is_type_item("Catalog")): 
                        self.root_object = (Utils.asObjectOrNull(self.__m_indirect_objs[i], PdfDictionary))
                        break
                i += 1
        if (self.info is None): 
            i = 1
            while i < len(self.__m_indirect_objs): 
                if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                    if (self.__m_indirect_objs[i].is_type_item("Info")): 
                        self.info = (Utils.asObjectOrNull(self.__m_indirect_objs[i], PdfDictionary))
                        break
                i += 1
        if (self.root_object is None): 
            i = 1
            while i < len(self.__m_indirect_objs): 
                if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                    if (self.__m_indirect_objs[i].is_type_item("XRef")): 
                        self.objs = list()
                        for v in self.__m_indirect_objs: 
                            if (v is not None): 
                                self.objs.append(v)
                        break
                i += 1
        if (self.root_object is not None): 
            self.root_object.get_all_pages(self.pages)
        i = 0
        while i < len(self.pages): 
            self.pages[i].page_num = (i + 1)
            i += 1
    
    def write_only_one_page(self, s : Stream, page_num : int) -> None:
        pdic = self.root_object.get_dictionary("Pages", None)
        count = Utils.asObjectOrNull(pdic.get_object("Count", False), PdfIntValue)
        if (count is not None): 
            count.val = 1
            count.id0_ = 0
        kids = Utils.asObjectOrNull(pdic.get_object("Kids", False), PdfArray)
        kids.clear()
        objs_ = list()
        id0__ = 1
        cur_page = None
        i = 1
        first_pass705 = True
        while True:
            if first_pass705: first_pass705 = False
            else: i += 1
            if (not (i < len(self.__m_indirect_obj_disp))): break
            obj = self.get_object(i)
            if (obj is None): 
                continue
            obj.deleted = True
            if (obj == self.pages[page_num] or obj == self.root_object or obj == self.info): 
                obj.deleted = False
                objs_.append(obj)
                obj.write_id = id0__
                id0__ += 1
                if (obj == self.pages[page_num]): 
                    cur_page = (Utils.asObjectOrNull(obj, PdfDictionary))
                    kids.add(PdfReference._new184(obj.write_id, obj.id0_))
        if (kids.id0_ > 0): 
            kids.deleted = False
            objs_.append(kids)
            kids.write_id = id0__
            id0__ += 1
        pdic.deleted = False
        objs_.append(pdic)
        pdic.write_id = id0__
        id0__ += 1
        cur_page.add_object("Parent", PdfReference._new184(pdic.write_id, pdic.id0_))
        refs = list()
        tmp = list()
        k = 0
        cou0 = 0
        k = 0
        while True: 
            cou = len(objs_)
            i = cou0
            while i < cou: 
                obj0 = objs_[i]
                if (obj0.id0_ == 378 or obj0.id0_ == 276): 
                    pass
                dic = Utils.asObjectOrNull(obj0, PdfDictionary)
                if (dic is not None): 
                    for key in dic.keys: 
                        if (key == "StructTreeRoot"): 
                            continue
                        obj = dic.get_object(key, False)
                        if (obj is None): 
                            continue
                        if (obj.deleted): 
                            if (obj.id0_ == 94): 
                                pass
                            if ((isinstance(obj, PdfDictionary)) and obj.is_type_item("Page")): 
                                continue
                            obj.deleted = False
                            objs_.append(obj)
                            obj.write_id = id0__
                            id0__ += 1
                            re = Utils.asObjectOrNull(dic.get_object(key, True), PdfReference)
                            if (re is not None): 
                                re.write_id = obj.write_id
                        elif (obj.id0_ == 0 and (((isinstance(obj, PdfDictionary)) or (isinstance(obj, PdfArray))))): 
                            objs_.append(obj)
                arr = Utils.asObjectOrNull(obj0, PdfArray)
                if (arr is not None): 
                    j = 0
                    first_pass706 = True
                    while True:
                        if first_pass706: first_pass706 = False
                        else: j += 1
                        if (not (j < arr.items_count)): break
                        obj = arr.get_item(j, False)
                        if (obj is None): 
                            continue
                        if (obj.deleted): 
                            if (obj.id0_ == 94): 
                                pass
                            if ((isinstance(obj, PdfDictionary)) and obj.is_type_item("Page")): 
                                continue
                            obj.deleted = False
                            objs_.append(obj)
                            obj.write_id = id0__
                            id0__ += 1
                            re = Utils.asObjectOrNull(arr.get_item(j, False), PdfReference)
                            if (re is not None): 
                                re.write_id = obj.write_id
                        elif (obj.id0_ == 0 and (((isinstance(obj, PdfDictionary)) or (isinstance(obj, PdfArray))))): 
                            objs_.append(obj)
                i += 1
            if (len(objs_) == cou): 
                break
            cou0 = cou
            k += 1
        buf = [ ]
        ii = 0
        ii = 0
        while ii < len(self.__m_head): 
            if (self.__m_head[ii] == (0xA)): 
                ii += 1
                break
            ii += 1
        s.write(self.__m_head, 0, ii)
        objs_count = 0
        for obj in objs_: 
            if (obj.id0_ == 0): 
                continue
            obj._write_pos = s.position
            objs_count += 1
            buf = "{0} 0 obj\r\n".format(obj.write_id).encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
            if (obj.deleted): 
                buf = "null".encode("ASCII", 'ignore')
                s.write(buf, 0, len(buf))
            else: 
                obj.write0_(s)
            buf = "\r\nendobj\r\n".encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
        xrefpos = s.position
        buf = "xref\r\n0 {0}\r\n0000000000 65535 f\r\n".format(objs_count + 1).encode("ASCII", 'ignore')
        s.write(buf, 0, len(buf))
        for obj in objs_: 
            if (obj.write_id > 0): 
                buf = "{0} 00000 n\r\n".format("{:01d}".format(obj._write_pos)).encode("ASCII", 'ignore')
                s.write(buf, 0, len(buf))
        if (self.trailer is None): 
            trailer_ = "trailer\r\n<</Size {0}".format(objs_count)
            if (self.info is not None): 
                trailer_ = "{0}/Info {1} 0 R".format(trailer_, self.info.write_id)
            if (self.root_object is not None): 
                trailer_ = "{0}/Root {1} 0 R".format(trailer_, self.root_object.write_id)
            trailer_ = "{0}>>\r\nstartxref\r\n{1}\r\n%%EOF".format(trailer_, xrefpos)
            buf = trailer_.encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
        else: 
            buf = "trailer\r\n".encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
            iii = Utils.asObjectOrNull(self.trailer.get_object("Size", False), PdfIntValue)
            if (iii is not None): 
                iii.val = len(objs_)
            if (self.trailer.get_object("Root", False) is None and self.root_object is not None): 
                self.trailer.add_object("Root", PdfReference._new186(self.root_object.write_id))
            if (self.trailer.get_object("Info", False) is None and self.info is not None): 
                self.trailer.add_object("Info", PdfReference._new186(self.info.write_id))
            self.trailer.write0_(s)
            buf = "\r\nstartxref\r\n{0}\r\n%%EOF".format(xrefpos).encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
    
    def write0_(self, s : Stream) -> None:
        buf = [ ]
        ii = 0
        ii = 0
        while ii < len(self.__m_head): 
            if (self.__m_head[ii] == (0xA)): 
                ii += 1
                break
            ii += 1
        s.write(self.__m_head, 0, ii)
        refs = list()
        objs_ = list()
        tmp = list()
        i = 1
        first_pass707 = True
        while True:
            if first_pass707: first_pass707 = False
            else: i += 1
            if (not (i < len(self.__m_indirect_obj_disp))): break
            obj = self.get_object(i)
            if (obj is None): 
                continue
            if (isinstance(obj, PdfDictionary)): 
                if (obj.is_type_item("XRef")): 
                    continue
            objs_.append(obj)
            obj.write_id = len(objs_)
            tmp.clear()
            obj.get_all_references(refs, tmp)
        for r in refs: 
            obj = self.get_object(r.id0_)
            if (obj is not None): 
                r.write_id = obj.write_id
        for obj in objs_: 
            obj._write_pos = s.position
            buf = "{0} 0 obj\r\n".format(obj.write_id).encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
            if (obj.deleted): 
                buf = "null".encode("ASCII", 'ignore')
                s.write(buf, 0, len(buf))
            else: 
                obj.write0_(s)
            buf = "\r\nendobj\r\n".encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
        xrefpos = s.position
        buf = "xref\r\n0 {0}\r\n0000000000 65535 f\r\n".format(len(objs_) + 1).encode("ASCII", 'ignore')
        s.write(buf, 0, len(buf))
        for obj in objs_: 
            buf = "{0} 00000 n\r\n".format("{:01d}".format(obj._write_pos)).encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
        if (self.trailer is None): 
            trailer_ = "trailer\r\n<</Size {0}".format(len(objs_))
            if (self.info is not None): 
                trailer_ = "{0}/Info {1} 0 R".format(trailer_, self.info.write_id)
            if (self.root_object is not None): 
                trailer_ = "{0}/Root {1} 0 R".format(trailer_, self.root_object.write_id)
            trailer_ = "{0}>>\r\nstartxref\r\n{1}\r\n%%EOF".format(trailer_, xrefpos)
            buf = trailer_.encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
        else: 
            buf = "trailer\r\n".encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
            iii = Utils.asObjectOrNull(self.trailer.get_object("Size", False), PdfIntValue)
            if (iii is not None): 
                iii.val = len(objs_)
            if (self.trailer.get_object("Root", False) is None and self.root_object is not None): 
                self.trailer.add_object("Root", PdfReference._new186(self.root_object.write_id))
            if (self.trailer.get_object("Info", False) is None and self.info is not None): 
                self.trailer.add_object("Info", PdfReference._new186(self.info.write_id))
            self.trailer.write0_(s)
            buf = "\r\nstartxref\r\n{0}\r\n%%EOF".format(xrefpos).encode("ASCII", 'ignore')
            s.write(buf, 0, len(buf))
        refs.clear()
        objs_.clear()
    
    def __read_all_resources(self) -> None:
        i = 1
        while i < len(self.__m_indirect_objs): 
            if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                dic = Utils.asObjectOrNull(self.__m_indirect_objs[i], PdfDictionary)
                sub = dic.get_string_item("Subtype")
                if (sub == "Image" or sub == "Font"): 
                    self.all_resources.append(dic)
            i += 1
    
    def __check_encrypt(self) -> bool:
        i = 1
        while i < len(self.__m_indirect_objs): 
            if (isinstance(self.__m_indirect_objs[i], PdfDictionary)): 
                dic = Utils.asObjectOrNull(self.__m_indirect_objs[i], PdfDictionary)
                if (dic.is_type_item("Encrypt")): 
                    self.encrypt = dic
                    return True
                self.encrypt = dic.get_dictionary("Encrypt", None)
                if (self.encrypt is not None): 
                    return True
            i += 1
        return False
    
    def close(self) -> None:
        if (self.__m_stream is not None): 
            self.__m_stream.close()
        self.__m_stream = (None)
    
    @property
    def max_objs_count(self) -> int:
        return len(self.__m_indirect_objs)
    
    def get_object(self, id0__ : int) -> 'PdfObject':
        if ((id0__ < 1) or id0__ >= len(self.__m_indirect_objs)): 
            return None
        if (self.__m_indirect_objs[id0__] is not None): 
            return self.__m_indirect_objs[id0__]
        if (self.__m_indirect_obj_disp[id0__] == 0): 
            return None
        if (id0__ == 6): 
            pass
        self.__m_stream.position = self.__m_indirect_obj_disp[id0__]
        uid = 0
        v = 0
        wrapuid190 = RefOutArgWrapper(0)
        wrapv191 = RefOutArgWrapper(0)
        inoutres192 = self.__m_stream.try_read_id_and_version(False, wrapuid190, wrapv191)
        uid = wrapuid190.value
        v = wrapv191.value
        if (not inoutres192): 
            return None
        if (uid != id0__): 
            return None
        obj = None
        try: 
            obj = self.__m_stream.parse_object(self, False)
        except Exception as ex: 
            pass
        if (obj is None): 
            return None
        obj.id0_ = id0__
        obj.version = v
        self.__m_indirect_objs[id0__] = obj
        return obj
    
    def __add_obj(self, id0__ : int, obj : 'PdfObject') -> None:
        while id0__ >= len(self.__m_indirect_objs):
            self.__m_indirect_objs.append(None)
            self.__m_indirect_obj_disp.append(0)
        self.__m_indirect_objs[id0__] = obj
    
    def __add_indir(self, id0__ : int, disp : int) -> None:
        while id0__ >= len(self.__m_indirect_objs):
            self.__m_indirect_objs.append(None)
            self.__m_indirect_obj_disp.append(0)
        self.__m_indirect_obj_disp[id0__] = disp
    
    def __read_xrefs(self) -> bool:
        if (self.__m_stream.length < 100): 
            return False
        self.__m_stream.position = self.__m_stream.length - 100
        str0_ = None
        while True:
            str0_ = self.__m_stream.read_word(True)
            if ((str0_) is not None): pass
            else: 
                break
            if (str0_ == "startxref"): 
                break
        if (str0_ is None): 
            return False
        str0_ = self.__m_stream.read_word(True)
        disp = 0
        wrapdisp199 = RefOutArgWrapper(0)
        inoutres200 = Utils.tryParseInt(str0_, wrapdisp199)
        disp = wrapdisp199.value
        if (not inoutres200): 
            return False
        inf_obj = None
        while True:
            if ((disp < 0) or disp >= self.__m_stream.length): 
                return False
            self.__m_stream.position = disp
            str0_ = self.__m_stream.read_word(False)
            if (str0_ != "xref"): 
                return False
            while True:
                id0 = 0
                count = 0
                i = 0
                str0_ = self.__m_stream.read_word(True)
                wrapid0197 = RefOutArgWrapper(0)
                inoutres198 = Utils.tryParseInt(str0_, wrapid0197)
                id0 = wrapid0197.value
                if (not inoutres198): 
                    break
                wrapcount195 = RefOutArgWrapper(0)
                inoutres196 = Utils.tryParseInt(self.__m_stream.read_word(True), wrapcount195)
                count = wrapcount195.value
                if (not inoutres196): 
                    break
                i = 0
                while i < count: 
                    w = self.__m_stream.read_word(True)
                    wrapdisp193 = RefOutArgWrapper(0)
                    inoutres194 = Utils.tryParseInt(w, wrapdisp193)
                    disp = wrapdisp193.value
                    if (not inoutres194): 
                        break
                    self.__m_stream.read_word(True)
                    str0_ = self.__m_stream.read_word(True)
                    if (str0_ is None or len(str0_) != 1): 
                        break
                    if (str0_ == "n"): 
                        self.__add_indir(id0, disp)
                    i += 1; id0 += 1
                if (i < count): 
                    break
            if (str0_ != "trailer"): 
                return False
            if (self.__m_stream.read_word(True) != "<"): 
                return False
            if (self.__m_stream.read_word(True) != "<"): 
                return False
            self.trailer = PdfDictionary()
            self.trailer.source_file = self
            self.trailer._post_parse(self.__m_stream)
            if (self.trailer.get_object("Encrypt", False) is not None): 
                self.encrypt = self.trailer.get_dictionary("Encrypt", None)
            if (self.root_object is None): 
                oo = self.trailer.get_object("Root", False)
                if (oo is not None): 
                    self.root_object = (Utils.asObjectOrNull(self.get_object(oo.id0_), PdfDictionary))
            if (inf_obj is None): 
                inf_obj = self.trailer.get_object("Info", True)
            d = 0
            prev = Utils.asObjectOrNull(self.trailer.get_object("Prev", False), PdfIntValue)
            if (prev is None): 
                break
            disp = prev.val
        if (inf_obj is not None): 
            self.info = (Utils.asObjectOrNull(self.get_object(inf_obj.id0_), PdfDictionary))
        return self.root_object is not None
    
    def __read_obj_stm(self, dic : 'PdfDictionary') -> bool:
        dat = dic.extract_data()
        if (dat is None or (len(dat) < 1)): 
            return False
        count = dic.get_int_item("N")
        if (count < 1): 
            return False
        with PdfStream(None, dat) as pstr: 
            ids = Utils.newArray(count, 0)
            disps = Utils.newArray(count, 0)
            i = 0
            while i < count: 
                id0__ = Utils.asObjectOrNull(pstr.parse_object(self, False), PdfIntValue)
                if (id0__ is None): 
                    break
                disp = Utils.asObjectOrNull(pstr.parse_object(self, False), PdfIntValue)
                if (disp is None): 
                    break
                ids[i] = (id0__.val)
                disps[i] = (disp.val)
                i += 1
            n0 = pstr.position
            i = 0
            while i < count: 
                pstr.position = n0 + disps[i]
                obj = pstr.parse_object(self, False)
                if (obj is not None): 
                    obj.id0_ = ids[i]
                    obj.source_file = self
                    self.__add_obj(obj.id0_, obj)
                    if (isinstance(obj, PdfDictionary)): 
                        if (obj.is_type_item("ObjStm")): 
                            pass
                i += 1
        return True
    
    def get_all_who_ref_object0(self, obj_id : int) -> typing.List['PdfObject']:
        res = list()
        ids = list()
        i = 1
        first_pass708 = True
        while True:
            if first_pass708: first_pass708 = False
            else: i += 1
            if (not (i < self.max_objs_count)): break
            o = self.get_object(i)
            if (o is None or o.id0_ == obj_id): 
                continue
            ids.clear()
            o.get_all_who_ref_object(obj_id, o, res, ids)
        return res
    def __enter__(self): return self
    def __exit__(self, typ, val, traceback): self.close()