Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix(ocr): improve image and table content extraction
myhlolib7e9d454e9e9
diff --git a/magic_pdf/dict2md/ocr_mkcontent.py b/magic_pdf/dict2md/ocr_mkcontent.pyindex 91f8faf4..5c189a18 100644--- a/magic_pdf/dict2md/ocr_mkcontent.py+++ b/magic_pdf/dict2md/ocr_mkcontent.py@@ -183,9 +183,10 @@ def para_to_standard_format_v2(para_block, img_buket_path, page_idx, drop_reasonpara_content = {'type': 'image', 'img_caption': [], 'img_footnote': []}for block in para_block['blocks']:if block['type'] == BlockType.ImageBody:- para_content['img_path'] = join_path(- img_buket_path,- block['lines'][0]['spans'][0]['image_path'])+ for line in block['lines']:+ for span in line['spans']:+ if span['type'] == ContentType.Image:+ para_content['img_path'] = join_path(img_buket_path, span['image_path'])if block['type'] == BlockType.ImageCaption:para_content['img_caption'].append(merge_para_with_text(block))if block['type'] == BlockType.ImageFootnote:@@ -194,11 +195,21 @@ def para_to_standard_format_v2(para_block, img_buket_path, page_idx, drop_reasonpara_content = {'type': 'table', 'table_caption': [], 'table_footnote': []}for block in para_block['blocks']:if block['type'] == BlockType.TableBody:+ for line in block['lines']:+ for span in line['spans']:+ if span['type'] == ContentType.Table:++ if span.get('latex', ''):+ para_content['table_body'] = f"\n\n$\n {span['latex']}\n$\n\n"+ elif span.get('html', ''):+ para_content['table_body'] = f"\n\n{span['html']}\n\n"++ if span.get('image_path', ''):+ para_content['img_path'] = join_path(img_buket_path, span['image_path'])if block["lines"][0]["spans"][0].get('latex', ''):para_content['table_body'] = f"\n\n$\n {block['lines'][0]['spans'][0]['latex']}\n$\n\n"elif block["lines"][0]["spans"][0].get('html', ''):para_content['table_body'] = f"\n\n{block['lines'][0]['spans'][0]['html']}\n\n"- para_content['img_path'] = join_path(img_buket_path, block["lines"][0]["spans"][0]['image_path'])if block['type'] == BlockType.TableCaption:para_content['table_caption'].append(merge_para_with_text(block))if block['type'] == BlockType.TableFootnote: