Comments (2)
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.
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)
- `find_tables()` is not detecting the only table on the page HOT 2
- pdf to image rendering ignore optional content offs HOT 6
- Saving into new PDF: "syntax error: expected object number" HOT 4
- ADD strikethrough to Markdown and HTML export HOT 7
- page.find_tables tab.cells and tab.extract() HOT 2
- Stories: Ordered list count broken with nested unordered list HOT 1
- Page value 0-based and 1-based are not unified HOT 1
- Add text alignment information to text extraction API HOT 1
- class improves namedDest handling HOT 2
- Extract Model Tree Info HOT 6
- truncated font names HOT 4
- Correct Text box is not picked up HOT 3
- get_images() smask value becomes 0 HOT 2
- test_bboxlog_2885 fails with (lib)mupdf 1.24.9 HOT 3
- inconsistent radio button group behavior in Adobe Reader vs Brave browser PDF viewer HOT 1
- i cannot get anything from this pdf,i cannot copy,cannot extract
- Partial OCR using "get_textpage_ocr" ignores image masks while extracting text HOT 3
- get_images() function doubt HOT 3
- Possible invalid interpretation of StructureTree information HOT 2
- Piximap program crash HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymupdf.