Giter VIP home page Giter VIP logo

Comments (2)

JorjMcKie avatar JorjMcKie commented on September 25, 2024

Incremental saves are not always possible: a number of situations will prevent this. Instead of trying / excepting you can check doc.can_save_incrementally() and only do an incremental save if True is returned.
The following script works flawlessly:

import pymupdf as fitz
doc=fitz.open("1.-.Copy.pdf")
doc.can_save_incrementally()
1
doc.is_repaired
False
for page in doc:
    _=page.get_text()
    print(f"Processed {page.number=}")

    
MuPDF error: format error: object (44 0 R) was not found in its object stream
MuPDF error: format error: object (35 0 R) was not found in its object stream
Processed page.number=0
Processed page.number=1
Processed page.number=2
Processed page.number=3
Processed page.number=4
Processed page.number=5
Processed page.number=6
Processed page.number=7
doc.is_repaired
True
doc.can_save_incrementally()
0
doc.ez_save("temp.pdf")
doc.close()
import os
os.remove(doc.name)

After a failing incremental save, obviously an additional reference count is added to the file handle which is not removed on closing the document. This happens on Windows only - no problem on Linux at least.

We will look into this. In the meantime, please use doc = None or del doc after closing. This will triger an additional reference count reduction and the removal will succeed.

from pymupdf.

ragebear00 avatar ragebear00 commented on September 25, 2024

many thanks! As you did again the beginning, doc.can_save_incrementally() is 1 before get_text(), just not realize the get_text() will cause "repair" and doc.can_save_incrementally() = false. Will check again before every saveIncr in the future.

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.