def concat(doc_left: Doc, doc_right: Doc, target_left: bool = True) -> Doc:
    """Add pages from doc_right at the end of doc_left.

    target_left arg specifies to which doc incremental update is applied
    """
    if target_left:
        new_doc = copy_doc(doc_left, revision='SAME')
        source_doc = doc_right
    else:
        new_doc = copy_doc(doc_right, revision='SAME')
        source_doc = doc_left
    mapping = {}
    start_num = max_num(new_doc) + 1
    cat, cat_iref = catalog(new_doc)
    source_doc = squash(source_doc)
    source_cat, source_cat_iref = catalog(source_doc)
    source_pages_iref = source_cat['/Pages']
    source_pages = get_object(source_doc, source_pages_iref)
    source_pcount = get_object(source_doc, source_pages['/Count'])
    source_doc = update_object(source_doc, int(source_cat_iref.imag), None)
    x_num = source_doc.index[-1][0].get('xref_stream_num')
    if x_num and x_num > 0:
        source_doc = update_object(source_doc, x_num, None)
    objs = in_use(source_doc)
    ir = complex(0, start_num)
    for iref in objs:
        mapping[iref] = ir
        ir += 1j
    for iref in objs:
        obj = get_object(source_doc, iref)
        new_obj = deep_ref_retarget(obj, mapping)
        new_doc, _ = add_object(new_doc, new_obj, immut=False)
    pages_iref = cat['/Pages']
    pages = get_object(new_doc, pages_iref)
    pcount = get_object(new_doc, pages['/Count'])
    kids = get_object(new_doc, pages['/Kids'])
    if target_left:
        kids.append(mapping[source_pages_iref])
    else:
        kids.insert(0, mapping[source_pages_iref])
    pages['/Kids'] = kids
    pages['/Count'] = pcount + source_pcount
    new_doc = update_object(new_doc, int(pages_iref.imag), pages, immut=False)
    return new_doc
Add pages from doc_right at the end of doc_left.

    target_left arg specifies to which doc incremental update is applied
    
pdfsyntax/docstruct.py