Improve Arabic/RTL PDF text extraction: logical reading order and table column associations are not preserved
Los mantenedores suelen responder en 1 día
@aslamalkarywk7 ya está trabajando en esto.
Desde el 18/9/2026.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 42/100
Línea de trabajo
Empieza con el convertidor PDF integrado mediante convert_stream(), usando la reproducción de Python proporcionada o el ejemplo de CLI markitdown arabic-brochure.pdf. Compara la salida extraída con el texto árabe esperado y las relaciones de las tablas, incluida una mezcla de árabe, números y URLs. Se considera terminado cuando el contenido RTL tiene un orden de lectura lógico, asociaciones correctas de tablas y secuencias LTR internas preservadas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Improve Arabic/RTL PDF text extraction: logical reading order and table column associations are not preserved
Description
MarkItDown's PDF converter does not reliably preserve the logical reading order of Arabic and other right-to-left (RTL) text.
In some PDFs, Arabic characters, words, lines, and table columns are extracted according to their visual placement in the PDF rather than their Unicode logical reading order. This can produce reversed text and, more importantly, incorrect relationships between table headers and values.
I observed this behavior with MarkItDown 0.1.3 and reproduced the reversed Arabic output with 0.1.7.
Example
Expected Arabic text:
تاريخ المزاد
مزاد ربى نجد
قطعة رقم 604 شمالاً
شركة أركان الكيان العقارية
Extracted output:
دازملا خيرات
داﺰـﻣ
ﺪﺠﻧ ﻰﺑر
604 مقر ةعطق لاً امش
ةيراقعلا نايكلا ناكرأ ةكرش
This appears to involve more than simple line ordering. Some text also contains Arabic Presentation Forms, and mixed Arabic/numeric sequences are reconstructed incorrectly.
Table extraction issue
The problem becomes more significant when extracting structured information from RTL tables.
For example, the source PDF may contain property boundaries equivalent to:
Direction | Boundary -- | -- North | Plot 604 South | Plot 602 East | Plot 597 West | 30-meter streetAfter conversion, the RTL table order is not preserved consistently. During downstream LLM extraction, boundary values were consequently assigned to the wrong directions.
For legal or property documents, this can materially change the meaning of the source data.
Impact on downstream LLM extraction
I compared two approaches:
Sending the original PDF directly to an LLM.
Converting the PDF to Markdown with MarkItDown and sending the resulting Markdown.
MarkItDown substantially reduced token usage and request time:
Native PDF input: 40,148 tokens
MarkItDown input: 22,604 tokens
Reduction: 17,544 tokens / 43.7%
Native PDF request time: 115.44 seconds
MarkItDown request time: 90.82 seconds
However, the extracted Markdown introduced material accuracy regressions, including:
Arabic city name
تميرbeing extracted or interpreted asتيمرA region becoming impossible to resolve correctly
Property boundary directions being reassigned
A plan number being malformed
The inferred auction type changing
Arabic descriptions containing reversed words and unnatural word order
The token savings are significant, but for documents containing legal identifiers, deed information, or property boundaries, these extraction errors can outweigh the efficiency benefit.
Reproduction
import iofrom markitdown import MarkItDown, StreamInfo
with open("arabic-brochure.pdf", "rb") as file:
pdf_bytes = file.read()converter = MarkItDown(enable_plugins=False)
result = converter.convert_stream(
io.BytesIO(pdf_bytes),
stream_info=StreamInfo(
mimetype="application/pdf",
extension=".pdf",
filename="arabic-brochure.pdf",
),
)
print(result.text_content)
The same general behavior occurs with the CLI:
markitdown arabic-brochure.pdf -o brochure.md
Expected behavior
For RTL PDFs, the converter should ideally:
Reconstruct Arabic text in Unicode logical reading order.
Normalize Arabic Presentation Forms where appropriate.
Preserve RTL word order without reversing the internal order of numbers, dates, URLs, or Latin text.
Preserve associations between table headers, columns, and cell values.
Correctly handle mixed-direction content such as Arabic combined with English, numbers, URLs, phone numbers, and legal identifiers.
Expose layout or confidence metadata when the logical reading order cannot be reconstructed reliably.
A simple character-level or string-level reversal would not be sufficient because an Arabic line may contain content such as:
رقم الرسم 604 / 2026 - https://example.com
The Arabic segments require RTL-aware reconstruction, while 604, 2026, and the URL must retain their internal LTR order.
Possible improvements
Potential approaches might include:
Applying Unicode Bidirectional Algorithm-aware processing during text reconstruction.
Detecting and normalizing Arabic Presentation Forms returned by the underlying PDF extraction layer.
Using glyph coordinates and writing direction to reconstruct RTL lines in logical order.
Detecting the dominant direction of table regions and ordering columns accordingly.
Adding a conversion option such as:
text_direction="auto" | "rtl" | "ltr"
Adding an RTL-specific post-processing stage for PDF extraction.
Emitting warnings or confidence metadata when reading order is ambiguous.
Adding Arabic/RTL PDF regression fixtures covering:
paragraphs
multi-column layouts
tables
Arabic + Latin text
numbers and dates
URLs
phone numbers
legal identifiers
Environment
Python:
3.10MarkItDown: reproduced with
0.1.3; reversed Arabic output also observed with0.1.7Platform: Linux
Input: multi-page Arabic real-estate auction brochure
Conversion: built-in PDF converter through
convert_stream()
Additional information
I can provide a redacted PDF and additional source-vs-extracted examples if that would help with reproducing the issue.
The test document contains Arabic paragraphs, property-information tables, legal identifiers, dates, phone numbers, and mixed RTL/numeric content.
- Lenguaje dominante
- Python
- Estrellas
- 198k
- Forks
- 15k
- Merge medio
- 2 h 16 min
- PR fusionados (30 d)
- 9
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/markitdown
-
IpynbConverter uses a comment inside a Markdown code fence as the notebook titlePosiblemente ocupada @Primaverah la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
microsoft/markitdown#2964 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
PPTX image alt text ending in a backslash breaks the Markdown imagePosiblemente ocupada @dongyikuan919 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/markitdown#2943 ·
Los mantenedores suelen responder en 1 día
-
PPTX chart labels with pipes or line breaks produce malformed Markdown tablesPosiblemente ocupada @dongyikuan919 la tomó hace 5 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
microsoft/markitdown#2937 ·
Los mantenedores suelen responder en 1 día
-
DOCX: math pre-processing re-parses every document.xml even without equations (32 s -> 17.5 s on a 12.5 MB document)Posiblemente ocupada @houyunsun la tomó hace 26 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 89/100
microsoft/markitdown#2834 ·
Los mantenedores suelen responder en 1 día
-
URL fetch sends default python-requests User-Agent, Wikipedia returns 403Posiblemente ocupada @sushan5140 la tomó hace 31 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/markitdown#2820 ·
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/markitdown
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
hugohe3/ppt-master#366 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 89/100
Los mantenedores suelen responder en 2 días
-
[开源推荐] 用 Claude 搭的 A 股投研与盘中作战系统Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
521xueweihan/HelloGitHub#4716 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
pcqpcq/open-source-android-apps#619 ·
Los mantenedores suelen responder en 1 día
-
contribution Windows 主机
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Lee-xeo/Claude-Cage#1519 ·
Los mantenedores suelen responder en 1 día