def force_xref_stream(doc: Doc, placeholder: bool = False, filt: str = '/FlateDecode') -> tuple:
    """Activate xref stream and optionally add placeholder at the end of current index."""
    if 'xref_stream_num' in doc.index[-1][0]:
        if '/Filter' in doc.cache[0] and doc.cache[0]['/Filter'] == filt:
            return doc
        else:
            new_doc = copy_doc(doc, revision='SAME')
    elif placeholder:
        new_doc, new_iref = add_object(doc, {})
        x_num = int(new_iref.imag)
        new_doc.index[-1][0] = deepcopy(new_doc.index[-1][0])
        new_doc.index[-1][0]['xref_stream_num'] = x_num
    else:
        new_doc = copy_doc(doc, revision='SAME')
        new_doc.index[-1][0] = deepcopy(new_doc.index[-1][0])
        new_doc.index[-1][0]['xref_stream_num'] = -1
    if filt:
        new_doc.cache[0]['/Filter'] = filt
    return new_doc
Activate xref stream and optionally add placeholder at the end of current index.
pdfsyntax/docstruct.py