PyPDF4 icon indicating copy to clipboard operation
PyPDF4 copied to clipboard

Bookmarks in merged pdf don't have a destination

Open edi-w opened this issue 5 years ago • 7 comments

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'))

edi-w avatar Aug 06 '20 12:08 edi-w

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,

pubpub-zz avatar Aug 10 '20 17:08 pubpub-zz

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

edi-w avatar Aug 14 '20 11:08 edi-w

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

pubpub-zz avatar Aug 14 '20 11:08 pubpub-zz

file1.pdf file2.pdf

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

edi-w avatar Aug 19 '20 08:08 edi-w

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

edi-w avatar Aug 21 '20 06:08 edi-w

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

pubpub-zz avatar Aug 21 '20 18:08 pubpub-zz

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

edi-w avatar Aug 24 '20 08:08 edi-w