mirror of
https://github.com/DS4SD/docling.git
synced 2025-08-01 15:02:21 +00:00
chore: Add example for inspection of picture content
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
This commit is contained in:
parent
1418fa1488
commit
687c469c6c
29
docs/examples/inspect_picture_content.py
Normal file
29
docs/examples/inspect_picture_content.py
Normal file
@ -0,0 +1,29 @@
|
||||
from docling_core.types.doc import TextItem
|
||||
|
||||
from docling.datamodel.base_models import InputFormat
|
||||
from docling.datamodel.pipeline_options import PdfPipelineOptions
|
||||
from docling.document_converter import DocumentConverter, PdfFormatOption
|
||||
|
||||
source = "tests/data/amt_handbook_sample.pdf"
|
||||
|
||||
pipeline_options = PdfPipelineOptions()
|
||||
pipeline_options.images_scale = 2
|
||||
pipeline_options.generate_page_images = True
|
||||
|
||||
doc_converter = DocumentConverter(
|
||||
format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
|
||||
)
|
||||
|
||||
result = doc_converter.convert(source)
|
||||
|
||||
doc = result.document
|
||||
|
||||
for picture in doc.pictures:
|
||||
# picture.get_image(doc).show() # display the picture
|
||||
print(picture.caption_text(doc), " contains these elements:")
|
||||
|
||||
for item, level in doc.iterate_items(root=picture, traverse_pictures=True):
|
||||
if isinstance(item, TextItem):
|
||||
print(item.text)
|
||||
|
||||
print("\n")
|
BIN
tests/data/amt_handbook_sample.pdf
Normal file
BIN
tests/data/amt_handbook_sample.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user