-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add example for inspection of picture content
Signed-off-by: Christoph Auer <[email protected]>
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
Binary file not shown.