Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/markitdown/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ all = [
"xlrd",
"lxml",
"pdfminer.six",
"pymupdf4llm",
"olefile",
"pydub",
"SpeechRecognition",
Expand All @@ -53,7 +54,7 @@ pptx = ["python-pptx"]
docx = ["mammoth", "lxml"]
xlsx = ["pandas", "openpyxl"]
xls = ["pandas", "xlrd"]
pdf = ["pdfminer.six"]
pdf = ["pdfminer.six", "pymupdf4llm"]
outlook = ["olefile"]
audio-transcription = ["pydub", "SpeechRecognition"]
youtube-transcription = ["youtube-transcript-api"]
Expand Down
12 changes: 12 additions & 0 deletions packages/markitdown/src/markitdown/converters/_pdf_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import BinaryIO, Any

import pymupdf4llm

from .._base_converter import DocumentConverter, DocumentConverterResult
from .._stream_info import StreamInfo
Expand Down Expand Up @@ -58,6 +59,7 @@ def convert(
**kwargs: Any, # Options to pass to the converter
) -> DocumentConverterResult:
# Check the dependencies

if _dependency_exc_info is not None:
raise MissingDependencyException(
MISSING_DEPENDENCY_MESSAGE.format(
Expand All @@ -72,6 +74,16 @@ def convert(
)

assert isinstance(file_stream, io.IOBase) # for mypy

use_pdf4llm = kwargs.get("use_pdf4llm", False)

if use_pdf4llm:
args_pdf4llm = kwargs.get("args_pdf4llm", {})

return DocumentConverterResult(
markdown=pymupdf4llm.to_markdown(file_stream, **args_pdf4llm)
)

return DocumentConverterResult(
markdown=pdfminer.high_level.extract_text(file_stream),
)