PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

Question / Comment: ImageBlock not detected

Open joctaTorres opened this issue 6 years ago • 4 comments

Hello :)

On this pdf page, extractDICT doesn't extract an ImageBlock for the wpt1 image XObject (check the image below).

Although from looking at the pdf content, (it seems to me that) this should have been extracted correctly as an ImageBlock:

image


The image is present on Page.getImageList():

(Pdb) type(page)
<class 'fitz.fitz.Page'>

(Pdb) page.getImageList() 
[(18, 0, 176, 100, 8, 'DeviceRGB', '', 'wpt1', 'FlateDecode')]

But no blocks with "type": 1 are detected:

(Pdb) [block for block in page.getTextPage().extractDICT()["blocks"] if block["type"] == 1]
[]

Am I doing something wrong? I'm using version 1.17.0. Thx for the support.

joctaTorres avatar May 20 '20 22:05 joctaTorres

Hm, all looks fine on my side:

>>> page=doc[0]
>>> doc.getPageImageList(0,True)
[(18, 0, 176, 100, 8, 'DeviceRGB', '', 'wpt1', 'FlateDecode', 0)]
>>> page.getImageBbox("wpt1")  # new functioanlity: also possible like before:
>>> # page.getImageBbox(doc.getPageImageList(0,True)[0])
Rect(101.27999877929688, 37.24005126953125, 185.0399932861328, 85.48004150390625)
>>> blocks=page.getText("dict")["blocks"]
>>> len(blocks)
9
>>> for b in blocks: print(b["type"])

0
1  # here is the image block
0
0
0
0
0
0
0
>>> b = blocks[1]
>>> b["bbox"]  # confirm it's the same size as above:
(101.27999877929688, 37.240028381347656, 185.0399932861328, 85.48002624511719)
>>> 

JorjMcKie avatar May 20 '20 23:05 JorjMcKie

@JorjMcKie

Using page.getText("dict")["blocks"] instead of page.getTextPage().extractDICT()["blocks"] worked just fine!

Thx for the support!

joctaTorres avatar May 21 '20 17:05 joctaTorres

Good to know ... but still disquieting. You may or may not know that the amount of data extracted can be influenced via the flags parameter. Because of what I did is just a wrapper for what you did, the results should be equal. So I will need look at what deviations for the flags defaults may exist between the two.

JorjMcKie avatar May 21 '20 17:05 JorjMcKie

Ah - now I understand: When you created the TextPage object yourself, you have propably not paid attention to the flags. Flags apply to TextPage creation time - not extraction time.

JorjMcKie avatar May 21 '20 17:05 JorjMcKie