Markdown - HTML - PDF - DOCX - RST - LaTeX - Reveal Slides
This PHP library offers a modern PHP wrapper for the Pandoc document converter.
composer require smnandre/pandoc
use Pandoc\Options;
use Pandoc\Pandoc;
use Symfony\Component\Finder\Finder;
// 1. Convert a single file with options:
$options = Options::create()
->setInput(['input.md'])
->setOutput('output.pdf')
->setFormat('pdf')
->tableOfContent();
Pandoc::create()->convert($options);
$finder = Finder::create()->files()->in('docs')->name('*.md');
$options = Options::create()
->setInput($finder)
->setOutputDir('output')
->setFormat('html');
Pandoc::create()->convert($options);
## Options
### Default Options
```php
$defaultOptions = Options::create()
->setFormat('html')
->tableOfContent();
$pandoc = Pandoc::create(defaultOptions: $defaultOptions);
Use default options, override output for this specific file:
$options = Options::create()->setInput(['chapter1.md'])->setOutput('chapter1.html');
$pandoc->convert($options);
$defaultOptions = Options::create()
->setInput(Finder::create()->files()->in('docs')->name('*.md'))
->setOutputDir('output')
->setFormat('html');
$pandoc = Pandoc::create(null, $defaultOptions);
$pandoc->convert(Options::create()); // Will use default options
$options = Options::create()
->setInput(['input.md'])
->setFormat('html')
->tableOfContent();
Pandoc::create()->convert($options);
- list input formats
- list output formats
Any contribution is welcome!
You can suggest new features or improvements by opening an RFC or a Pull Request on the GitHub repository of Pandoc PHP.
If you encounter any issues, please open an issue on the GitHub repository of Pandoc PHP.
Before submitting a Pull Request, make sure to run the following commands, and that they all pass.
If you have any questions, feel free to ask on the GitHub repository of Pandoc PHP.
php vendor/bin/php-cs-fixer check
php vendor/bin/phpstan analyse
php vendor/bin/phpunit
Pandoc PHP is maintained by Simon André
Pandoc is a project by John MacFarlane and contributors.## Contributing
This project is licensed under the MIT License - see the LICENSE file for details.