[PR #4832] Add the ability to parse PDF tables, pictures, and cross-page tables #24660

Closed
opened 2026-02-21 20:23:26 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/4832

State: closed
Merged: No


Description

Using the enhanced open parsing library to parse PDF documents, you can maintain the table style of the PDF document, and also extract image content, table content, cross-page tables, etc. in the PDF, while trying to ensure that it meets the user's reading order.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

To test the PDF parsing function individually, use the following code, Use pdfmimer algorithm
`from core.rag.extractor.pdf.openparse import DocumentParser, processing
from core.rag.extractor.pdf.openparse.schemas import ImageElement

if name == 'main':
"""Lazy load given path as pages."""
# blob = Blob.from_path(self._file_path)
# yield from self.parse(blob)
file_path = "pdf file path here"
documents = []
parser = DocumentParser(
processing_pipeline=processing.BasicIngestionPipeline(),
table_args={
"parsing_algorithm": "pdfmimer",
"table_output_format": "markdown"
}
)
parsed_basic_doc = parser.parse(file_path)
documentContent = ''
for _index, node in enumerate(parsed_basic_doc.nodes):
metadata = {"source": file_path, "page": _index}
for element in node.elements:
if isinstance(element, ImageElement):
# pdf images a
pass
else:
print(element.text)`

there is ImageElement\ TableElement\TextElement
If you parse the image, the focus is ImageElement, which has the following attributes that can be used
block: dict
text: str
image: bytes
ext: str
bbox: Bbox

**Original Pull Request:** https://github.com/langgenius/dify/pull/4832 **State:** closed **Merged:** No --- # Description Using the enhanced open parsing library to parse PDF documents, you can maintain the table style of the PDF document, and also extract image content, table content, cross-page tables, etc. in the PDF, while trying to ensure that it meets the user's reading order. # How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration To test the PDF parsing function individually, use the following code, Use pdfmimer algorithm `from core.rag.extractor.pdf.openparse import DocumentParser, processing from core.rag.extractor.pdf.openparse.schemas import ImageElement if __name__ == '__main__': """Lazy load given path as pages.""" # blob = Blob.from_path(self._file_path) # yield from self.parse(blob) file_path = "pdf file path here" documents = [] parser = DocumentParser( processing_pipeline=processing.BasicIngestionPipeline(), table_args={ "parsing_algorithm": "pdfmimer", "table_output_format": "markdown" } ) parsed_basic_doc = parser.parse(file_path) documentContent = '' for _index, node in enumerate(parsed_basic_doc.nodes): metadata = {"source": file_path, "page": _index} for element in node.elements: if isinstance(element, ImageElement): # pdf images a pass else: print(element.text)` there is ImageElement\ TableElement\TextElement If you parse the image, the focus is ImageElement, which has the following attributes that can be used block: dict text: str image: bytes ext: str bbox: Bbox
yindo added the pull-request label 2026-02-21 20:23:26 -05:00
yindo closed this issue 2026-02-21 20:23:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#24660