MCPcopy
hub / github.com/ArtifexSoftware/pdf2docx / ImageBlock

Class ImageBlock

pdf2docx/image/ImageBlock.py:17–81  ·  view source on GitHub ↗

Image block.

Source from the content-addressed store, hash-verified

15
16
17class ImageBlock(Image, Block):
18 '''Image block.'''
19 def __init__(self, raw:dict=None):
20 super().__init__(raw)
21
22 # inline image type by default
23 self.set_inline_image_block()
24
25
26 def to_text_block(self):
27 """Convert image block to a span under text block.
28
29 Returns:
30 TextBlock: New TextBlock instance containing this image.
31 """
32 # image span
33 span = ImageSpan().from_image(self)
34
35 # add span to line
36 image_line = Line()
37 image_line.add(span)
38
39 # insert line to block
40 block = TextBlock()
41 block.add(image_line)
42
43 # NOTE: it's an image block even though in TextBlock type
44 block.set_inline_image_block()
45
46 return block
47
48
49 def store(self):
50 '''Store ImageBlock instance in raw dict.'''
51 res = Block.store(self)
52 res.update(
53 Image.store(self)
54 )
55 return res
56
57
58 def plot(self, page):
59 '''Plot image bbox with diagonal lines (for debug purpose).
60
61 Args:
62 page (fitz.Page): pdf page to plot.
63 '''
64 super().plot(page, color=(1,0,0))
65
66
67 def make_docx(self, p):
68 '''Create floating image behind text.
69
70 Args:
71 p (Paragraph): ``python-docx`` paragraph instance.
72
73 .. note::
74 Inline image is created within TextBlock.

Callers 3

_restore_float_imagesMethod · 0.90
restoreMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…