@@ -4098,7 +4098,10 @@ def _with_embedded_pictures(self) -> "DoclingDocument":
40984098 return result
40994099
41004100 def _with_pictures_refs (
4101- self , image_dir : Path , reference_path : Optional [Path ] = None
4101+ self ,
4102+ image_dir : Path ,
4103+ page_no : Optional [int ],
4104+ reference_path : Optional [Path ] = None ,
41024105 ) -> "DoclingDocument" :
41034106 """Document with images as refs.
41044107
@@ -4111,7 +4114,7 @@ def _with_pictures_refs(
41114114 image_dir .mkdir (parents = True , exist_ok = True )
41124115
41134116 if image_dir .is_dir ():
4114- for item , level in result .iterate_items (with_groups = False ):
4117+ for item , level in result .iterate_items (page_no = page_no , with_groups = False ):
41154118 if isinstance (item , PictureItem ):
41164119
41174120 if (
@@ -4211,7 +4214,7 @@ def save_as_json(
42114214 os .makedirs (artifacts_dir , exist_ok = True )
42124215
42134216 new_doc = self ._make_copy_with_refmode (
4214- artifacts_dir , image_mode , reference_path = reference_path
4217+ artifacts_dir , image_mode , page_no = None , reference_path = reference_path
42154218 )
42164219
42174220 out = new_doc .export_to_dict (
@@ -4254,7 +4257,7 @@ def save_as_yaml(
42544257 os .makedirs (artifacts_dir , exist_ok = True )
42554258
42564259 new_doc = self ._make_copy_with_refmode (
4257- artifacts_dir , image_mode , reference_path = reference_path
4260+ artifacts_dir , image_mode , page_no = None , reference_path = reference_path
42584261 )
42594262
42604263 out = new_doc .export_to_dict (
@@ -4327,7 +4330,7 @@ def save_as_markdown(
43274330 os .makedirs (artifacts_dir , exist_ok = True )
43284331
43294332 new_doc = self ._make_copy_with_refmode (
4330- artifacts_dir , image_mode , reference_path = reference_path
4333+ artifacts_dir , image_mode , page_no , reference_path = reference_path
43314334 )
43324335
43334336 md_out = new_doc .export_to_markdown (
@@ -4503,7 +4506,7 @@ def save_as_html(
45034506 os .makedirs (artifacts_dir , exist_ok = True )
45044507
45054508 new_doc = self ._make_copy_with_refmode (
4506- artifacts_dir , image_mode , reference_path = reference_path
4509+ artifacts_dir , image_mode , page_no , reference_path = reference_path
45074510 )
45084511
45094512 html_out = new_doc .export_to_html (
@@ -4542,14 +4545,15 @@ def _make_copy_with_refmode(
45424545 self ,
45434546 artifacts_dir : Path ,
45444547 image_mode : ImageRefMode ,
4548+ page_no : Optional [int ],
45454549 reference_path : Optional [Path ] = None ,
45464550 ):
45474551 new_doc = None
45484552 if image_mode == ImageRefMode .PLACEHOLDER :
45494553 new_doc = self
45504554 elif image_mode == ImageRefMode .REFERENCED :
45514555 new_doc = self ._with_pictures_refs (
4552- image_dir = artifacts_dir , reference_path = reference_path
4556+ image_dir = artifacts_dir , page_no = page_no , reference_path = reference_path
45534557 )
45544558 elif image_mode == ImageRefMode .EMBEDDED :
45554559 new_doc = self ._with_embedded_pictures ()
0 commit comments