Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export loses outlines #22

Open
ghost opened this issue Jun 8, 2018 · 9 comments
Open

Export loses outlines #22

ghost opened this issue Jun 8, 2018 · 9 comments

Comments

@ghost
Copy link

ghost commented Jun 8, 2018

Hi thanks for this great tool!

I'm trying to export my Mendeley library and noticing that my outlines/bookmarks are missing from the output. These are useful for me to navigate around my documents. Is it possible to retain these in the export? Thanks for your help.

@Xunius
Copy link
Owner

Xunius commented Jun 9, 2018

Hi apenewberry,

I didn't know about the outlines/bookmarks feature of Mendeley. I just updated my version to 1.19 which should be latest, but still I don't quite get it. Can you give me some more hint regarding the outlines you are referring to? What version are you using, is it windows or Mac or Linux?

@ghost
Copy link
Author

ghost commented Jun 9, 2018

I'm using Mendeley Desktop 1.19 on Ubuntu 17.10.

I think they're called 'outlines' or 'bookmarks' in the PDF format, but Mendeley displays them in the Contents tab of the sidebar on the right. Screenshot below.

I've been looking at some resources, but haven't figured out how copy the outlines in:

image

@Xunius
Copy link
Owner

Xunius commented Jun 9, 2018

I see. So these are embedded in the PDFs aren't they? And they appear in more recent publications not in older ones. So how do you want them to be exported? Because the pdf files are merely copied to the target folder, if a pdf has these, the export should too.

@ghost
Copy link
Author

ghost commented Jun 9, 2018

Ok I think I must've made a mistake. I'll look into this further and update.

@ghost
Copy link
Author

ghost commented Jun 9, 2018

It looks like the script copies the bookmarks for most PDFs but misses them on (at least one) others. I'm not sure what the distinguishing characteristic is for when it misses them. I think I'll just deal with the few missed examples manually as they come up. Thanks for the tool and for responding so quickly as well -- cheers!

@Xunius
Copy link
Owner

Xunius commented Jun 9, 2018

Hmm it's strange that it fails for certain pdfs. Could it have something to do with the pdf viewer software?

@ghost
Copy link
Author

ghost commented Jun 9, 2018

I'm not sure. Apparently there are multiple ways to embed bookmarks in PDFs, which can make reading them complicated, but it's getting over my head at that point.

@syu-id
Copy link

syu-id commented Oct 2, 2019

Hi, this is my quick solution which seems to work without problems:

# 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})
diff --git a/lib/exportpdf.py b/lib/exportpdf.py
index 5072681..aaffe23 100644
--- a/lib/exportpdf.py
+++ b/lib/exportpdf.py
@@ -154,6 +154,14 @@ def exportPdf(fin,outdir,annotations,verbose):
 
         outpdf.addPage(inpg)
 
+
+    # 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})
+
     #-----------------------Save-----------------------
     filename=annotations.filename
     if not os.path.isdir(outdir):

@Xunius
Copy link
Owner

Xunius commented Oct 4, 2019

@RongMu thanks for providing the fix. I've incorporated your code. As I'm not going to test it myself I've put the snippet in a try block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants