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

Bookmarks in merged pdf don't have a destination #87

Open
edi-w opened this issue Aug 6, 2020 · 7 comments
Open

Bookmarks in merged pdf don't have a destination #87

edi-w opened this issue Aug 6, 2020 · 7 comments

Comments

@edi-w
Copy link

edi-w commented Aug 6, 2020

When merging pdf files, the bookmarks from sourcefiles are inherited correctly but they don't point to any page. Also bookmarks that are created while appending files to the merger don't have a destination. I'm using python 3.7.6.

Example:
merger = PdfFileMerger()
merger.append(PdfFileReader(filepath,'rb'),bookmark='test',pages=None,import_bookmarks=True)
merger.write(open(outfile, 'wb'))

@pubpub-zz
Copy link

Hi,
I'm currently preparing a new version in a fork. It seems to work for me

Can you give me your feed back with my proposed version ?(not yet released but attached in here)

pypdf4-1.27.0PPzz_1-py2.py3-none-any.whl.zip

thanks,

@edi-w
Copy link
Author

edi-w commented Aug 14, 2020

Hi,

I tried that but get this:

merger.append(filepath)

File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 146, in append
self.merge(None, fileobj, bookmark, pages, import_bookmarks)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 116, in merge
self._copy_bookmarks(fileobj.root_object["/Outlines"], bkmark, srcpages)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 171, in _copy_bookmarks
self.copy_bookmarks(cur, bkmark1, srcpages)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 171, in _copy_bookmarks
self.copy_bookmarks(cur, bkmark1, srcpages)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 171, in _copy_bookmarks
self.copy_bookmarks(cur, bkmark1, srcpages)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 160, in _copy_bookmarks
if Destination("", node).pageref.idnum in srcpages:
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\generic.py", line 2205, in init
pdf.get_named_destinations()[page_or_dest_or_array].get_dest_array()
UnboundLocalError: local variable 'pdf' referenced before assignment

@pubpub-zz
Copy link

I've just made a test similar to yours successfully.
Your trouble may be linked with the content of your pdf file. Is it possible to have a copy?
Thks

@edi-w
Copy link
Author

edi-w commented Aug 19, 2020

file1.pdf
file2.pdf

Here's example files with blank pages. I get the same error with these.

@edi-w
Copy link
Author

edi-w commented Aug 21, 2020

Thanks, I tried and it worked as expected with those files. However, if I append the attached file, I get the following error:

Traceback (most recent call last):
File "pdflistmerge.py", line 13, in
merger.append(filepath)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 146, in append
self.merge(None, fileobj, bookmark, pages, import_bookmarks)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 116, in merge
self._copy_bookmarks(fileobj.root_object["/Outlines"], bkmark, srcpages)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\merger.py", line 162, in _copy_bookmarks
if Destination("", node).pageref.idnum in srcpages:
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\generic.py", line 2196, in init
pdf = page_or_dest_or_array.rawGet("/Parent").pdf
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\pypdf\generic.py", line 409, in rawGet
return dict.getitem(self, key)
KeyError: '/Parent'
file3.pdf

@pubpub-zz
Copy link

Hi Edi-w,
I have to appologize, I've seen your problem just after posting the message, that's why I deleted it.
This should work now:
pypdf4-1.27.0PPzz_1-py2.py3-none-any.whl.zip

@edi-w
Copy link
Author

edi-w commented Aug 24, 2020

Hi,
as far as I can tell, that seems to be working exactly as expected. Thanks!

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