
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
This package converts the pages of a PDF to text in Markdown format using PyMuPDF.
Standard text and tables are detected, brought in the right reading sequence and then together converted to GitHub-compatible Markdown text.
Header lines are identified via the font size and appropriately prefixed with one or more '#' tags.
Bold, italic, mono-spaced text and code blocks are detected and formatted accordingly. Similar applies to ordered and unordered lists.
By default, all document pages are processed. If desired, a subset of pages can be specified by providing a list of 0-based page numbers.
$ pip install -U pymupdf4llm
This command will automatically install PyMuPDF if required.
Then in your script do:
import pymupdf4llm
md_text = pymupdf4llm.to_markdown("input.pdf")
# now work with the markdown text, e.g. store as a UTF8-encoded file
import pathlib
pathlib.Path("output.md").write_bytes(md_text.encode())
Instead of the filename string as above, one can also provide a PyMuPDF Document
. By default, all pages in the PDF will be processed. If desired, the parameter pages=[...]
can be used to provide a list of zero-based page numbers to consider.
Feature Overview:
Support for pages with multiple text columns.
Support for image and vector graphics extraction:
pymupdf4llm.to_markdown("input.pdf", write_images=True)
. Default is False
."input.pdf-pno-index.extension"
in a folder of your choice. The image extension
can be chosen to represent a PyMuPDF-supported image format (for instance "png" or "jpg"), pno
is the 0-based page number and index
is some sequence number.dpi
(default: dpi=150
).force_text=False
(text only apears as part of the image).Support for page chunks: Instead of returning one large string for the whole document, a list of dictionaries can be generated: one for each page. Specify data = pymupdf4llm.to_markdown("input.pdf", page_chunks=True)
. Then, for instance the first item, data[0]
will contain a dictionary for the first page with the text and some metadata.
As a first example for directly supporting LLM / RAG consumers, this version can output LlamaIndex documents:
import pymupdf4llm
md_read = pymupdf4llm.LlamaMarkdownReader()
data = md_read.load_data("input.pdf")
# The result 'data' is of type List[LlamaIndexDocument]
# Every list item contains metadata and the markdown text of 1 page.
data[0].to_dict().["text"]
.LlamaMarkdownReader
all necessary LlamaIndex-related imports are executed. Required related package installations must have been done independently and will not be checked during pymupdf4llm installation.FAQs
PyMuPDF Utilities for LLM/RAG
We found that pymupdf4llm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.