Laravel bindings for markitdown.
You can install the package via composer:
composer require innobrain/markitdown
Install the markitdown package from pip.
pip install markitdown
You will need to have markitdown
available as a binary in your command line.
⚡ The recommended way to do this is to use pipx
:
On macOS:
brew install pipx
pipx ensurepath
sudo pipx ensurepath --global # optional to allow pipx actions with --global argument``
Or see how to install on other platforms.
After installling pipx
, you can install markitdown
with:
pipx install markitdown
Now, set the path to the markitdown
executable in your .env
file. You can retrieve the path with:
which markitdown
MARKITDOWN_EXECUTABLE=/path/to/markitdown
Also, when running the script anywhere but the console, you need to set the PATH, as php-fpm does not have
access to the PATH variable. You can do this by adding the following to your .env
file:
echo $PATH
MARKITDOWN_SYSTEM_PATH=<your path>
You can publish the config file with:
php artisan vendor:publish --tag="markitdown-config"
This is the contents of the published config file:
return [
/*
* Use this to set the timeout for the process. Default is 30 seconds.
*/
'process_timeout' => env('MARKITDOWN_PROCESS_TIMEOUT', 30),
/*
* Use this to set the path to the markitdown executable. If not set,
* the binary will be searched in the PATH.
*/
'executable' => env('MARKITDOWN_EXECUTABLE', 'markitdown'),
/*
* This is needed when you want to run markitdown in php-fpm. One dependency
* of markitdown requires PATH to be set. If you are running in a console,
* this is not needed.
*/
'system' => [
'path' => env('MARKITDOWN_SYSTEM_PATH', ''),
],
/*
* The path where temporary files will be stored. This directory must be writable
* by the web server. Defaults to storage/app/private/markitdown_tmp
*/
'temporary_directory' => env('MARKITDOWN_TEMPORARY_DIRECTORY', storage_path('app/private/markitdown_tmp')),
];
// convert a file:
$markdown = \Innobrain\Markitdown\Facades\Markitdown::convert('/path/to/file.docx');
// or convert a file you already have in memory:
$file = file_get_contents('/path/to/file.docx');
$markdown = \Innobrain\Markitdown\Facades\Markitdown::convertFile($file, '.docx');
composer test
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.