Menu

#39 Multiple definitions in dictionary error message

v1.0 (example)
open
logari81
None
5
2019-07-11
2015-01-20
PaulM
No

Hi,

When trying to combine a number of PDF documents and save, I get an error message saying "multiple definitions in dictionary". I've used pdfshuffler for a number of years and I've never seen this issue. I'm running on Ubuntu 14.04 64, which has version 0.6.0 by default.

Any ideas what could be causing this?

Thanks
Paul

Discussion

  • logari81

    logari81 - 2015-01-20

    Could you run pdfshuffler in a terminal and post here the whole output of the program when the error occurs?

     
    • PaulM

      PaulM - 2015-01-20

      I was running in a terminal. There were no error messages. The above mentioned message came up as a message in a window.

       
  • logari81

    logari81 - 2015-01-20

    yes, I assumed this would be a pypdf issue, since pypdf is quite unmaintained.

    In the yet to be released version 0.7 of pdfshuffler:
    http://svn.gna.org/viewcvs/pdfshuffler/trunk/
    the program will by default try to use pypdf2 if it is installed on your system.

    It would be interesting to see if the bug you are experiencing also occurs with pypdf2 or not.

     
    • PaulM

      PaulM - 2015-01-20

      Unfortunately pypdf2 is not in the standard repositories. I could install it manually...

      Will look forward to seeing 0.7 in the future.

      Out of interest would the poppler library work instead of pypdf, I think it's quite active?

       
  • logari81

    logari81 - 2015-01-20

    pypdf2 is available in debian, so maybe you can use a package from debian.

    In any case if you want to test pypdf2 you have to replace the line

    from pyPdf import PdfFileWriter, PdfFileReader
    

    in pdfshuffler.py, with:

    from PyPDF2 import PdfFileWriter, PdfFileReader
    

    Regarding poppler, it is already used in pdfshuffler but its function is to render pdf files, not to manipulate them.

     
  • Niklas Vainio

    Niklas Vainio - 2015-07-07

    PyPDF2 is available as python-pypdf2 on Ubuntu 15.04.

    I tried the manual change to pdfshuffler.py described above. The problem was not solved but the error message is now "Multiple definitions in dictionary at byte 0x306 for key /Type".

     
  • lawn owner

    lawn owner - 2015-08-20

    Mint 17.1 x64 || Linux 3.13.0-37-generic || gcc 4.8.2 || pyPdf 1.13-1

    Within the file /usr/share/pyshared/pyPdf/generic.py, at lines 523-526:

    FROM:

    if data.has_key(key):
    # multiple definitions of key not permitted
    raise utils.PdfReadError, "multiple definitions in dictionary"
    data[key] = value

    TO:

    if not data.get(key):
    data[key] = value

    Indentation before "data[key] = value" is required, otherwise you get "IndentationError: expected an indented block".

     

    Last edit: lawn owner 2015-08-20
    • Raman Gupta

      Raman Gupta - 2016-01-04

      Thanks, that worked for me too on Fedora 23.

       
    • Jason Statham

      Jason Statham - 2016-11-02

      I'm on Mint 18, using python 2.7.11, pyPdf 1.13-3. If you cannot find the file /usr/share/pyshared/pyPdf/generic.py, try to search in /usr/lib/python2.7/dist-packages/pyPdf/generic.py same line number.

       
  • gwarah

    gwarah - 2017-02-04

    Today I've got the same problem. Try to run on terminal and got no messages. I'm under ubuntu 16.04.

    Some pdfs it processes ok; others not. Unfortunetly I can't send these files because they have private information.

    Update: I've applied these patch suggested above and it seems fix the bugs . In my station (ubuntu 16.04) I've followed these steps

    1) edit the file with sudo privileges: sudo vi /usr/lib/python2.7/dist-packages/pyPdf/generic.py
    2) go to line 523.
    3) fix the code at this way:

               # cut these lines
                if data.has_key(key):
                    # multiple definitions of key not permitted
                     raise utils.PdfReadError, "multiple definitions in dictionary"
                data[key] = value
    
                # replace with these ones
                if not data.has_key(key):
                    data[key] = value
    
     

    Last edit: gwarah 2017-02-07
  • Robert Leleu

    Robert Leleu - 2017-02-04

    Using pdfshuffler 0.6.0 at least once per month under Ubuntu 16.10 for 4 pages dcuments, I never encountered this bug

     
    • gwarah

      gwarah - 2017-02-05

      my pdfshuffler is also 0.6.0 but my ubuntu is 16.04. So, please, could you try to join these 2 pdf that cause the program fail and post the results?

      please, run by a terminal and post the messages here, too.

      Tks a lot.

       

      Last edit: gwarah 2017-02-05
    • gwarah

      gwarah - 2017-02-05

      see an important update in my last post above. It seems it's a bug.

       
  • DoodleDude

    DoodleDude - 2018-01-15

    Here is a one-liner to fix the bug.

    (For the directory, put your location of the generic.py file. This script also creates a backup generic.py.bak, in case you want to get back to previous bugged state for whatever reason.)

    In terminal, copy and paste this and don't forget to change your directory, because it is different in some distros!! Do a search for pyPdf and you will find the directory of generic.py

    directory=/usr/lib/python2.7/dist-packages/pyPdf ; sudo sed -i.bak 's/            if data.has_key(key):/            if not data.get(key):/g' $directory/generic.py; sudo sed -i '/              # multiple definitions of key not permitted/d' $directory/generic.py; sudo sed -i '/               raise utils.PdfReadError, "multiple definitions in dictionary"/d' $directory/generic.py; sudo sed -i 's/data\[key\] = value/    data\[key\] = value/g' $directory/generic.py
    

    As far as I heard, this has been fixed in later Python versions, but Ubuntu keeps using the old 2.7 version, which works otherwise fine, if not counting for this peculiarity.

     

    Last edit: DoodleDude 2018-01-15
  • Bright-Tech

    Bright-Tech - 2019-07-11

    Experianced the same issue with pdfshuffler on chromebook with debian stretch in crostini

    Operating System: Debian GNU/Linux 9 (stretch)
    Kernel: Linux 4.19.26-03278-g71dc68f9c9d0
    Architecture: x86-64

    python-pypdf2 1.26.0-2

    pdfshuffler 0.6.0-8

    I commented out similar lines in /usr/lib/python2.7/dist-packages/PyPDF2/generic.py which seems to have resolved the issue.

            if not data.get(key):
                data[key] = value
           # 
           # elif pdf.strict:
           #     # multiple definitions of key not permitted
           #     raise utils.PdfReadError("Multiple definitions in dictionary at byte %s for key %s" \
           #                                % (utils.hexStr(stream.tell()), key))
           # else:
           #     warnings.warn("Multiple definitions in dictionary at byte %s for key %s" \
           #                                % (utils.hexStr(stream.tell()), key), utils.PdfReadWarning)
    
     

Log in to post a comment.