@@ -2427,7 +2427,10 @@ def _with_embedded_pictures(self) -> "DoclingDocument":
2427
2427
return result
2428
2428
2429
2429
def _with_pictures_refs (
2430
- self , image_dir : Path , reference_path : Optional [Path ] = None
2430
+ self ,
2431
+ image_dir : Path ,
2432
+ page_no : Optional [int ],
2433
+ reference_path : Optional [Path ] = None ,
2431
2434
) -> "DoclingDocument" :
2432
2435
"""Document with images as refs.
2433
2436
@@ -2440,7 +2443,7 @@ def _with_pictures_refs(
2440
2443
image_dir .mkdir (parents = True , exist_ok = True )
2441
2444
2442
2445
if image_dir .is_dir ():
2443
- for item , level in result .iterate_items (with_groups = False ):
2446
+ for item , level in result .iterate_items (page_no = page_no , with_groups = False ):
2444
2447
if isinstance (item , PictureItem ):
2445
2448
2446
2449
if (
@@ -2515,7 +2518,7 @@ def save_as_json(
2515
2518
os .makedirs (artifacts_dir , exist_ok = True )
2516
2519
2517
2520
new_doc = self ._make_copy_with_refmode (
2518
- artifacts_dir , image_mode , reference_path = reference_path
2521
+ artifacts_dir , image_mode , page_no = None , reference_path = reference_path
2519
2522
)
2520
2523
2521
2524
out = new_doc .export_to_dict ()
@@ -2554,7 +2557,7 @@ def save_as_yaml(
2554
2557
os .makedirs (artifacts_dir , exist_ok = True )
2555
2558
2556
2559
new_doc = self ._make_copy_with_refmode (
2557
- artifacts_dir , image_mode , reference_path = reference_path
2560
+ artifacts_dir , image_mode , page_no = None , reference_path = reference_path
2558
2561
)
2559
2562
2560
2563
out = new_doc .export_to_dict ()
@@ -2615,7 +2618,7 @@ def save_as_markdown(
2615
2618
os .makedirs (artifacts_dir , exist_ok = True )
2616
2619
2617
2620
new_doc = self ._make_copy_with_refmode (
2618
- artifacts_dir , image_mode , reference_path = reference_path
2621
+ artifacts_dir , image_mode , page_no , reference_path = reference_path
2619
2622
)
2620
2623
2621
2624
md_out = new_doc .export_to_markdown (
@@ -2775,7 +2778,7 @@ def save_as_html(
2775
2778
os .makedirs (artifacts_dir , exist_ok = True )
2776
2779
2777
2780
new_doc = self ._make_copy_with_refmode (
2778
- artifacts_dir , image_mode , reference_path = reference_path
2781
+ artifacts_dir , image_mode , page_no , reference_path = reference_path
2779
2782
)
2780
2783
2781
2784
html_out = new_doc .export_to_html (
@@ -2812,14 +2815,15 @@ def _make_copy_with_refmode(
2812
2815
self ,
2813
2816
artifacts_dir : Path ,
2814
2817
image_mode : ImageRefMode ,
2818
+ page_no : Optional [int ],
2815
2819
reference_path : Optional [Path ] = None ,
2816
2820
):
2817
2821
new_doc = None
2818
2822
if image_mode == ImageRefMode .PLACEHOLDER :
2819
2823
new_doc = self
2820
2824
elif image_mode == ImageRefMode .REFERENCED :
2821
2825
new_doc = self ._with_pictures_refs (
2822
- image_dir = artifacts_dir , reference_path = reference_path
2826
+ image_dir = artifacts_dir , page_no = page_no , reference_path = reference_path
2823
2827
)
2824
2828
elif image_mode == ImageRefMode .EMBEDDED :
2825
2829
new_doc = self ._with_embedded_pictures ()
0 commit comments