cycomanic / Menextract2pdf

Extract Mendely annotations to PDF FIles
GNU General Public License v3.0
35 stars 15 forks source link

Table of contents missing in converted files #19

Open syu-id opened 4 years ago

syu-id commented 4 years ago

Table of contents / outline of PDF files is not preserved after conversion. This would make it very difficult to navigate some long articles.

syu-id commented 4 years ago

Here is my quick solution, which copies the root of the original PDF to the output after annotations are merged.

# insert after the line:
# outpdf = add_annotation2pdf(inpdf, outpdf, annotations)

# Copy the root (document catalog) except for /Pages
# PDF Reference, Sixth Edition, version 1.7, p.137
# https://www.adobe.com/devnet/pdf/pdf_reference_archive.html
for k,v in inpdf.trailer["/Root"].items():
    if k.getObject() != "/Pages":
        outpdf._root_object.update({k: v})

See also: Xunius/Menotexport#22