Giter VIP home page Giter VIP logo

Comments (8)

julian-smith-artifex-com avatar julian-smith-artifex-com commented on July 21, 2024 3

Fixed in 1.24.5.

from pymupdf.

JorjMcKie avatar JorjMcKie commented on July 21, 2024

You must provide an example where this happens. Otherwise we cannot accept this bug report.

from pymupdf.

YYTB avatar YYTB commented on July 21, 2024

how about this
my method got wrong

    def merge_pdfs(self, file_list: List[Union[Path, str]]):
        if len(file_list) == 1:
            self.merge_doc = fitz.open(file_list[0])
        else:
            self.merge_doc = fitz.open()
            merged_toc = []
            for file in tqdm(file_list, desc="merge", unit="file"):
                pdf = fitz.open(file)
                merged_toc.append((1, Path(file).stem.replace("\u3000", ""), len(self.merge_doc) + 1))
                self.merge_doc.insert_file(pdf)
                pdf.close()
            self.merge_doc.set_toc(merged_toc, collapse=0)
            self.merge_doc.save(self.out_pdf_file)
        self.add_metadata()
        self.set_file_view()
        if self.pagenum:
            self.add_pagnums()
        if self.watermark:
            self.add_watermark(self.watermark_text)
        self.merge_doc.save(self.out_pdf_file)

error message, it stays in 1.24.4, but in 1.24.2 don't have these errors.

..\venv\lib\site-packages\pymupdf\__init__.py:87:exception_info: exception_info:
Traceback (most recent call last):
  File "D:\JDBDocuments\Pycharm\table_name_cards\venv\lib\site-packages\pymupdf\utils.py", line 1444, in set_toc
    txt += ol["dest"]
KeyError: 'dest'
..\venv\lib\site-packages\pymupdf\__init__.py:87:exception_info: exception_info:
Traceback (most recent call last):
  File "D:\JDBDocuments\Pycharm\table_name_cards\venv\lib\site-packages\pymupdf\utils.py", line 1462, in set_toc
    if ol["next"] > -1:
KeyError: 'next'
..\venv\lib\site-packages\pymupdf\__init__.py:87:exception_info: exception_info:
Traceback (most recent call last):
  File "D:\JDBDocuments\Pycharm\table_name_cards\venv\lib\site-packages\pymupdf\utils.py", line 1469, in set_toc
    if ol["parent"] > -1:
KeyError: 'parent'
..\venv\lib\site-packages\pymupdf\__init__.py:87:exception_info: exception_info:
Traceback (most recent call last):
  File "D:\JDBDocuments\Pycharm\table_name_cards\venv\lib\site-packages\pymupdf\utils.py", line 1476, in set_toc
    if ol["prev"] > -1:
KeyError: 'prev'
..\venv\lib\site-packages\pymupdf\__init__.py:87:exception_info: exception_info:
Traceback (most recent call last):
  File "D:\JDBDocuments\Pycharm\table_name_cards\venv\lib\site-packages\pymupdf\utils.py", line 1483, in set_toc
    txt += "/Title" + ol["title"]
KeyError: 'title'

Thank you guys for your hard work

from pymupdf.

JorjMcKie avatar JorjMcKie commented on July 21, 2024

Apologies - I should have looked into this myself!

from pymupdf.

YYTB avatar YYTB commented on July 21, 2024

Apologies - I should have looked into this myself!

I tried to fix this in your source code but failed. If it is not too much trouble to ask, can you explain why this happened?

from pymupdf.

NamelessUzer avatar NamelessUzer commented on July 21, 2024

I also encountered the same problem. It was so easy to reproduce the error by trying to bookmark a PDF file.
Here is a code that can reproduce this bug.

import fitz
from pathlib import Path

pdf = Path(r'test.pdf')
toc = [(1, 'level1', 1), (2, 'level2', 1)]
doc = fitz.open(pdf)
doc.set_toc(toc, collapse = 2)

from pymupdf.

julian-smith-artifex-com avatar julian-smith-artifex-com commented on July 21, 2024

I think this may be the same as #3479.

Internal exception diagnostics in utils.py were increased in 1.24.2.

The fix is simple enough. But i'm also looking at writing a test that checks that we don't generate such diagnostics in future.

from pymupdf.

ChuanPoLee avatar ChuanPoLee commented on July 21, 2024

I got the same error message when doing doc.set_toc(toc_list).
pymupdf version: 1.24.4
python version: 3.11.7
os: windows

I add key check in utils.py before next 5 variables assign ( I'm not sure if this is a good method.)
ol["dest"] (add if 'dest' in ol: ...)
ol["next"]
ol["parent"]
ol["prev"]
ol["title"]

from pymupdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.