Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

PdfFileMerger fails while building Destination #14

Description

@jkbgbr

Dear all,

I recently got a new scanner (Xerox 6515) and pages scanned into pdfs using the device can not be merged with other pdfs.

Minimal example (example_page.pdf):

from PyPDF3 import PdfFileMerger
pdf_merger = PdfFileMerger()
pdfs_to_merge = ['E:\\modules\\pdfMerger\\10 - example_page.pdf']

for f in pdfs_to_merge:
    pdf_merger.append(f)

Traceback:

Traceback (most recent call last):
  File "E:/modules/pdfMerger/minimal_example.py", line 7, in <module>
    pdf_merger.append(f)
  File "E:\modules\venv\v3\lib\site-packages\PyPDF3\merger.py", line 203, in append
    self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
  File "E:\modules\venv\v3\lib\site-packages\PyPDF3\merger.py", line 151, in merge
    outline = pdfr.getOutlines()
  File "E:\modules\venv\v3\lib\site-packages\PyPDF3\pdf.py", line 1481, in getOutlines
    outline = self._buildOutline(node)
  File "E:\modules\venv\v3\lib\site-packages\PyPDF3\pdf.py", line 1563, in _buildOutline
    outline = self._buildDestination(title, dest)
  File "E:\modules\venv\v3\lib\site-packages\PyPDF3\pdf.py", line 1544, in _buildDestination
    return Destination(title, page, typ, *array)
  File "E:\modules\venv\v3\lib\site-packages\PyPDF3\generic.py", line 1060, in __init__
    self[NameObject("/Zoom")]) = args
ValueError: not enough values to unpack (expected 3, got 2)

The content of args is a tuple with two PyPDF3.generic.NullObjects.
Monkey-patching at line 1058 to

# from table 8.2 of the PDF 1.7 reference.

if typ == "/XYZ":
    args += (args[1],)  # extending args to avoid ValueError
    (self[NameObject("/Left")], self[NameObject("/Top")],
        self[NameObject("/Zoom")]) = args

leads to a full run, that is, my code works as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions