使用 Pypdf 在 pdf 中添加修改过的大纲词典

问题描述 投票:0回答:0

使用 pypdf 合并多个 pdf 时,我不得不增加 pdf 中所有书签的页码

outlines = pdf_reader.outline
                            print("old outline",outlines)
                            increment_value = int(total_pages)
                            print("increased by",increment_value)
                            for outline in outlines:
                                page_key = NameObject('/Page')
                                if page_key in outline:
                                    current_page_number = outline[page_key]
                                    new_page_number = NumberObject(current_page_number + increment_value)
                                    outline.update({page_key: new_page_number})

                            print("Modified outlines:", outlines)

                            pdf_writer.append(input_file,import_outline=False)
                            for outline in outlines:
                                print("show single outline",outline)

                                # add the modifiedoutline
                                pdf_writer.add_outline(outline,outline[page_key])

尝试添加修改后的大纲,不工作抛出错误, TypeError: PdfWriter.add_outline() 采用 1 个位置参数,但给出了 3 个

输出

如何将修改后的大纲添加到pdf

python pypdf bookmarks
© www.soinside.com 2019 - 2024. All rights reserved.