- Major rework of OCR support:
- Tesseract-OCR is now supported as a plugin in the
ocrinstallation folder. - OCR support has been reworked to automatically choose the most appropriate OCR engine combination, depending on the availability of Python package rapidocr_onnxruntime and Tesseract's language support files ("tessdata").
- Parameter
force_ocr=Truedoes no longer require to specifyocr_function. If no OCR function is given, the best available plugin is chosen. An exception is raised only if none of the plugins is usable.
- Tesseract-OCR is now supported as a plugin in the
Pymupdf4llm now automatically installs and uses pymupdf_layout.
-
Installing the pympdf4llm package automatically installs pymupdf_layout.
- We now specify an exact versions of pymupdf, instead of (as previously) pymupdf>=1.27.1.
- We specify an exact version of pymupdf_layout.
-
import pymupdf4llmwill automatically initialise layout. -
Layout can be disabled by calling
pymupdf4llm.use_layout(False). -
Our release numbering scheme has been changed to comply with the other packages in the PyMuPDF family.
- 356 - Page Chunk Output under to_text() may fail for erroneous layout bboxes
- Added support for RapidOCR via a callable plugin.
- Added support for improved OCR via a combination of RapidOCR and Tesseract-OCR.
- Changed default DPI for OCR to 300 (was 400).
- Added new parameter
ocr_function=None. If notNoneit must be a callable, which is expected to OCR the page giving it a text layer. - Added new parameter
force_ocr=Falseto all extraction functions. Requires to also provide a callable viaocr_function. IfTrue,ocr_functionis called for every page, thus skipping the otherwise executed "OCR worthiness" check.
- 356 - Page Chunk Output under to_text() may fail for erroneous layout bboxes
- 355 - Image saving fails if the document filename contains folder specifications
- Added new top-level function
get_key_values()to extract the field name and their values if the document is a "Form PDF". This is always available, whether or not PyMuPDF-Layout is avtive. - Removed OpenCV dependency. Previously, this was used to determine whether a page is worthwhile to be OCR'd. We now use numpy for these checks.
- 349 - Is it possible to change the OCR language when using -layout?
- 352 - Does not respect the image_path keyword argument when write_images=True
- 353 - How do I filter out pixmap with non-empty size but empty in value
-
Support new parameter
ocr_language. This is a string which is passed through to Tesseract-OCR, so the user is responsible for its format. -
Changed the format of the page chunk dictionary: the new dictionary key "page_boxes" in layout mode is now a list of dictionaries (was a list of lists). The dictionaries have the following keys / values:
-
"index": 0-based integer enumerating the layout boxes in reading order
-
"class": a string denoting the bbox class ("table", "list-item", "section-header", etc.)
-
"bbox": pymupdf.IRect of the layout boundary box
-
"pos": tuple
(start, stop)of integers denoting the text substring of the bboxes text in this chunk's text ("text" key of the chunk). The values are in slice format and can be used to extract the bbox text like thisbbox_text = chunk["text"][start : stop].
-
-
Implemented multiple performance improvements, primarily around rectangle containment checks.
- 323 -
page_chunks=Trueparameter was ignored in PyMuPDF-Layout mode
- Methods
to_markdown()/to_text()now both support Page chunk output via parameterpage_chunks=True.
- Forum - List index out of range ...
- 341 - Broken markdown parsing for new line directly followed by 'o'...
- New parameter
table_formatin methodto_text()(PyMuPDF-Layout only). This allows selecting the appearance of tables in plain text outputs. The possible values are defined in the listtabulate.tabulate_formats. Default is "grid". - Installing PyMuPDF4LLM now supports including all optional dependencies in the
pipcommand:pip install --upgrade pymupdf4llm[ocr,layout]. This will install pymupdf4llm, pymupdf, and pymupdf-layout. The "ocr" parameter - when needed - installs opencv-python for automatic OCR support in PyMuPDF-Layout mode. Combine this with parameters--upgrade,--force-reinstallor--no-cache-diras necessary. - Major rework of the heuristics that determine whether a page should be OCR'd.
- 335 - KeyError "has_ocr_text"
- 332 - TypeError("to_markdown() got an unexpected keyword argument 'header'")
- Output (backend) methods now accept a new parameter
ocr_dpi=400which sets the OCR resolution for full-page OCR. - The OCR detection heuristics is more fine-grained and now detects more OCR situations.
- Resolved multiple performance issues, specifically cases with overwhelmingly many images and extremely large
StructTreeRootobjects in PDF. - Reflected layout-specific API changes in the legacy code and will now raise
NotImplementedErrorexceptions when layout-only features are used. - Information messages during document parsing are now written to stdout collectively at the end of the phase. This applies to announcing page OCR decisions specifically.
- Support parameter
page_separatorsas in the legacy mode.
- 320 - [Bug] ValueError: min() iterable argument is empty ...
- 319 - [Bug] ValueError: min() arg is an empty sequence
- OCR invocation now differentiates between full-page OCR and text-only OCR: If the page does contain text but the percentage of unreadable characters exceeds a certain threshold (90%), we only OCR text span boundary boxes and replace span text with OCR'ed text where necessary.
This version introduces full support of the PyMuPDF-Layout package. This entails a radically new approach for detecting the layout of document pages using the AI-based features of the layout package.
Improvements include:
- Greatly improved table detection
- Support of list item hierachy levels
- Detection of page headers and footers
- Improved detection of text paragraphs, titles and section headers
- New output options beyond Markdown: plain text and JSON
- Automatically detect whether a page needs OCR and invoke Tesseract if both, Tesseract is installed and OpenCV (package opencv-python) is available. Invocation criteria include absence of readable text, full-page coverage with images, presence of many character-sized vector graphics.
The PyMuPDF-Layout package is not open-source and has its own license, which is different from PyMuPDF4LLM. It also is dependent on a number of other, fairly large packages like onnxruntime, numpy, sympy and OpenCV, which each in turn have their own dependencies.
We therefore keep the use of the layout feature optional. To activate PyMuPDF-Layout support the following import statement must be included before importing PyMuPDF4LLM itself:
import pymupdf.layout
import pymupdf4llmThereafter, PyMuPDF's namespace is available. The known method pymupdf4llm.to_markdown() automatically works with AI-based empowerment.
In addition, two new methods become available:
pymupdf4llm.to_text()- which works much like markdown output but produces plain text.pymupdf4llm.to_json()- which outputs the document's metadata and the selected pages in JSON format.
- If
show_progress=True, Python package tqdm is automatically used when available to display a progress bar. If tqdm is not installed, our own text-based progress bar is used.
- 296 - [Bug] A specific diagram recognized as significant ...
- 294 - Unable to extract images from Page
- 272 - Disappeared page breaks
- Added new parameter to
to_markdown:page_separators=False. IfTrueandpage_chunks=Falsea line like--- end of page=nnn ---is appended to each pages markdown text. The page number is 0-based. Intended for debugging purposes.
- 289 - Content Duplication with the latest version
- 275 - Text with background missing from output
- 262 - Markdown error parsing
-
The table module in package PyMuPDF has been modified: Its method
to_markdown()will now output markdown-styled cell text. Previously, table cells were extracted as plain text only. -
The class
TocHeadersis now a top-level import and can now be directly used. -
Method
to_markdownhas a new parameterdetect_bg_color=True(default) which guesses the page's background color. If a background is detected, fill-only vectors having this color are ignored.Falsewill always consider "fill" vectors in vector graphics detection. -
Text written with a
Type 3font will now always be considered. Previously, this text was always treated as invisible and was hence suppressed. -
The package now contains the license file GNU Affero GPL 3.0 to ease distribution (see LICENSE). It also clarifies that PyMuPDF4LLM is dual licensed under GNU AGPL 3.0 and individual commercial licenses.
-
There is a new file
versions_file.pywhich contains version information. This is used to ensure the presence of a minimum PyMuPDF version at import time.
- 282 - Content Duplication with the latest version
- 281 - Latest version of pymupdf4llm.to_markdown returns empty text for some PDFs.
- 280 - Cannot extract text when ignore_images=False, can extract otherwise.
- 278 - Title words are fragmented
- 249 - Title duplication problem in markdown format
- 202 - BAD RECT ISSUE
-
The table module in package PyMuDDF has been: Its method
to_markdown()will now output markdown-styled cell text. Previously, table cells were extracted as plain text only. -
The class
TocHeadersis now a top-level import and can now be directly used. -
Text written with a
Type 3font will now always be considered. Previously, this text was always treated as invisible and was hence suppressed.
- Fixing "UnboundLocalError"
- 265 - Code error correction
- 263 - Table Strategy = None raises error
- 261 - wrong markdown in latest pymupdf versions
- Highspeed vector graphics count: if
graphics_limitis specified, drawings are no longer extracted for counting purposes.
- 251 - Images a little larger than the page size are being ignored
- 255 - Single-row/column tables are skipped
- 258 - Pymupdf4llm to_markdown crashes on some documents
- Added class
TocHeadersas an alternative way for identifying headers.
- 116 - Handling Graphical Images & Superscripts
- 171 - Text rects overlap with tables and images that should be excluded.
- 189 - The position of the extracted image is incorrect
- 238 - When text is laid out around the picture, text extraction is missing.
-
Added new parameter
ignore_images: (bool) optional.Truewill not consider images in any way. May be useful for pages where a plethora of images prevents meaningful layout analysis. Typical examples are PowerPoint slides and derived / similar pages. -
Added new parameter
ignore_graphics: (bool), optional.Truewill not consider graphics except for table detection. May be useful for pages where a plethora of vector graphics prevents meaningful layout analysis. Typical examples are PowerPoint slides and derived / similar pages. -
Added new parameter to class
IdentifyHeaders: Usemax_levels(integer <= 6) to limit the generation of header tag levels. e.g.headers = pymupdf4llm.IdentifyHeaders(doc, max_level=3)ensures that only up to 3 header levels will ever be generated. Any text with a font size less than the value of###will be body text. In this case, the markdown generation itself would be coded asmd = pymupdf4llm.to_markdown(doc, hdr_info=headers, ...). -
Changed parameter
table_strategy: When specifyingNone, no effort to detecting tables will be made. This can be useful when tables are of no interest or known to not exist in a given file. This will speed up processing significantly. Be prepared to see more changes and extensions here.
The following list includes fixes made in version 0.0.18 already.
- 158 - Very long titles when converting to markdown.
- 155 - Inconsistent image extraction from image-only PDFs
- 161 - force_text param ignored.
- 162 - to_markdown isn't outputting all the pages but get_text is.
- 173 - First column of table is repeated before the actual table.
- 187 - Unsolicited Text Particles
- 188 - Takes lot of time to convert into markdown.
- 191 - Extraction of text stops in the middle while working fine with PyMuPDF.
- 212 - In pymupdf4llm, if a page has multiple images, only 1 image per-page is extracted.
- 213 - Many ���� after converting when using pymupdf4llm
- 215 - Spending too much time on identifying text bboxes
- 218 - IndexError in get_raw_lines when processing PDFs with formulas
- 225 - Text with background missing from output.
- 229 - Duplicated Table Content on pymuPDF4LLM.
-
Added new parameter
filename: (str), optional. Overwrites or sets the filename for saved images. Useful when the document is opened from memory. -
Added new parameter
use_glyphs: (bool), optional. Request to use the glyph number (if possible) of a character if the font has no back-translation to the original Unicode value. The default isFalsewhich causes � symbols to be rendered in these cases. -
Added strike-out support: We now detect and render
striked-out text. -
Improved background color detection: We have introduced a simple background color detection mechanism: If a page shows an identical color in all four corners, we assume this to be the background color. Text and vector graphics with this color will be ignored as invisible.
-
Improved invisible text detection: Text with an alpha value of 0 is now ignored.
-
Improved fake-bold detection: Text mimicking bold appearance is now treated like standard bold text in most cases.
-
Header handling changes:
- Detection now happens based on the largest font size of the line.
- Uniformly rendered: All spans of a header line will now be rendered with the same appearance.
-
Changed handling of parameter
graphics_limit: We previously ignored a page completely if the vector graphics count exceeded the limit. We now only ignore vector graphics if their count outside table boundary boxes is too large. This should only suppress vector graphics on the page, while keeping images, text and table content extractable. -
Changed the
marginsdefault to 0. The previous default(0, 50, 0, 50)ignored 50 points at the top and bottom of pages. This has turned out to cause confusion in too many cases.
- 147 - Error when page contains nothing but a table.
- 81 - Issues with bullet points in PDFs.
- 78 - multi column pdf file text extraction.
- 138 - Table is not extracted and some text order was wrong.
- 135 - Problem with multiple columns in simple text.
- 134 - Exclude images based on size threshold parameter.
- 132 - Optionally embed images as base64 string.
- 128 - Enhanced image embedding format.
- New parameter
embed_images(bool) embeds images and vector graphics in the markdown text as base64-encoded strings. Ignoreswrite_imagesandimage_pathparameters. - New parameter
image_size_limitwhich is a float between 0 and 1, default is 0.05 (5%). Causes images to be ignored if their width or height values are smaller than the corresponding fraction of the page's width or height. - The algorithm has been improved which determins the sequence of the text rectangles on multi-column pages.
- Change of the header identification algorithm: If more than six header levels are required for a document, then all text with a font size larger than body text is assumed to be a header of level 6 (i.e. HTML "h6" = "###### ").
- 112 - Invalid bandwriter header dimensions/setup.
- New parameter
ignore_codesuppresses special formatting of text in mono-spaced fonts. - New parameter
extract_wordsenforcespage_chunks=Trueand adds a "words" list to each page dictionary.
- Extended the list of known bullet point characters.
- 73 - bug in
to_markdowninternal function. - 74 - minimum area for images & vector graphics.
- 75 - Poor Markdown Generation for Particular PDF.
- 76 - suggestion on useful api parameters.
- Improved recognition of "insignificant" vector graphics. Graphics like text highlights or borders will be ignored.
- The format of saved images can now be controlled via new parameter
image_format. - Images can be stored in a specific folder via the new parameter
image_path. - Images are not stored if contained in another image on same page.
- Images are not stored if too small: if width or height are less than 5% of corresponding page dimension.
- All text is always written. If
write_images=True, text on images / graphics can be suppressed by settingforce_text=False.
- 71 - Unexpected results in pymupdf4llm but pymupdf works.
- 68 - Issue with text extraction near footer of page.
- Improved identification of scattered text span particles. This should address most issues with out-of-sequence situations.
- We now correctly process rotated pages (see issue 68).
- 65 - Fix typo in
pymupdf_rag.py.
- 54 - Mistakes in orchestrating sentences. Additional fix: text extraction no longer uses the
TEXT_DEHYPHENATEflag bit.
- Improved the algorithm dealing with vector graphics. Vector graphics are now more reliably classified as irrelevant: We now detect when "strokes" only exist in the neighborhood of the graphics boundary box border itself. This is quite often the case for code snippets.
- 55 - Bug in helpers/multi_column.py - IndexError: list index out of range.
- 54 - Mistakes in orchestrating sentences.
- 52 - Chunking of text files.
- Partial fix for 41 / 40 - Improved page column detection, but still no silver bullet for overly complex page layouts.
- New parameter
dpito specify the resolution of images. - New parameters
page_width/page_heightfor easily processing reflowable documents (Text, Office, e-books). - New parameter
graphics_limitto avoid spending runtimes for value-less content. - New parameter
table_strategyto directly control the table detection strategy.