使用 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