Comments (4)
For whatever reason, some of your text_instances
rectangles have a width of 0 - this causes the division by zero exception.
So you can check / ignore such rectangles yourself.
But of course the code must also be immunized against such nonsense-input.
from pymupdf.
For whatever reason, some of your
text_instances
rectangles have a width of 0 - this causes the division by zero exception. So you can check / ignore such rectangles yourself. But of course the code must also be immunized against such nonsense-input.
Thanks !
This leads to another question...
The search_for method returns very odd placements (Rect) of words searched for (ie not at all the place where the word is located in the pdf...).
Is there something I can do to actually search for words and return the right spots or is it too difficult ?
from pymupdf.
The success of text searching is dependent on that text is indeed stored in a searchable way. That may not be the case at all! Even if a page looks utterly harmless.
For a demo look at these two files, file1, file2. Both look exactly equal - and in fact, every character is positioned at the exact same place in both of them.
But ...
doc1=pymupdf.open("textmaker.pdf")
doc2=pymupdf.open("textmaker2.pdf")
page1 = doc1[0]
page2 = doc2[0]
needle = "alignment." # some text to search for
page1.search_for(needle)
[Rect(205.07913208007812, 158.3671875, 257.65399169921875, 172.76171875),
Rect(91.0791244506836, 158.3671875, 143.65399169921875, 172.76171875)]
page2.search_for(needle)
[]
You will never find any word in file2, however, single characters are no problem.
The solution of this riddle: for demo purposes, characters have been deliberately written on the page in some random sequence.
Text searching contains no precaution to extract single characters and sort them in "natural reading sequence" (what is that anyway?) before finally searching for something. The performance of such an approach would make it unattractive.
So when searching, you implicitly trust that a page has been created in some reasonable way, that the PDF creator has been too lazy to make it difficult.
But there are exceptions: e.g. whenever you use redaction annotations to replace text, then the new text will be an example for out-of-sequence words / characters. This is inevitable with PDF.
We have to live with it.
from pymupdf.
Ok, I got it, very clear. Thanks !
from pymupdf.
Related Issues (20)
- SegFault 11 when empty H1 H2 H3 H4 etc element is used in insert_htmlbox HOT 2
- PyMuPDF apply_redactions crops parts of the PDF in the final output HOT 7
- page.links return all links with same xref, is it something possible ?? HOT 6
- Invalid OCGs not ignored by SVG image creation HOT 1
- Redaction Annotation Fill Not Matching Up With Redacted Section HOT 4
- Updating Annotations HOT 1
- False result when finding bounding boxes for lines in blocks. HOT 6
- For what reason IRect exists? HOT 1
- MuPDF error: argument error: not a dict (string) HOT 3
- Get image inside table's cell
- `'width'` in `Page.get_drawings()` returns width equal as 0 HOT 1
- trouble in page.find_tables HOT 1
- Garbled extraction for Amazon Sustainability Report HOT 3
- This pdf would cause stack overflow exception, HOT 3
- ImportError: DLL load failed while importing _extra: The specified module could not be found. HOT 1
- Story.fit_width() has a weird line HOT 1
- The position box obtained through the get_text() method is inaccurate HOT 5
- ObjStm compression and PDF linearization doesn't work together HOT 3
- SMask of Image is not detected HOT 4
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.